Home Reference Source Repository
import {State} from 'monad-ts/src/state.js'
public class | source

State

Extends:

Monad → State

Indirect Implements:

Class State - it takes a state and returns an intermediate value and some new state value.

Constructor Summary

Public Constructor
public

Creates an instance of the class State with an initialization or not, the initialization can be occur late with bind method.

Member Summary

Public Members
public

The instance of ErrorM.

public

The instance of Maybe.

public

state: any

Keeps the state of application variables.

Method Summary

Public Methods
public

bind(f: Function, v: *)

It takes an initial state of the monad if monad has initialized in the constructor then function assigns Error to underlying value.

public

get(): Pr<T> | Error

Extracts the state of app.

public

put(f: function(v: T))

Changes the state of application variables, if you try add new key with put() to state object it'll be assigned with Error instance.

Inherited Summary

From class Monad
public abstract

bind(f: MF<T, U>|D<T>, v: *): Promise<U> | Pr<U> | Error | boolean | void

Binds transformation function and underlying value to the monad.

protected

fail(e: Error | string): Error

Takes Error or string return Error.

protected

just(f: function(v: T), v: T): Pr<U>

Produces result after execution f(v).

Public Constructors

public constructor(state: Object) source

Creates an instance of the class State with an initialization or not, the initialization can be occur late with bind method.

Params:

NameTypeAttributeDescription
state Object
  • optional

the initial state of app.

Public Members

public err: ErrorM source

The instance of ErrorM.

public maybe: Maybe source

The instance of Maybe.

public state: any source

Keeps the state of application variables.

Public Methods

public bind(f: Function, v: *) source

It takes an initial state of the monad if monad has initialized in the constructor then function assigns Error to underlying value.

Override:

Monad#bind

Params:

NameTypeAttributeDescription
f Function
v *
  • optional

underlying value for the monad, it can be null.

public get(): Pr<T> | Error source

Extracts the state of app.

Return:

Pr<T> | Error

public put(f: function(v: T)) source

Changes the state of application variables, if you try add new key with put() to state object it'll be assigned with Error instance.

Params:

NameTypeAttributeDescription
f function(v: T)

app. state transformation function.