monad-ts
Version:
Monad-ts is a small library implements some of key monads and way to chain them in a pipe (flow) in JavaScript and TypeScript. Angular 2+ compatible.
51 lines (50 loc) • 1.59 kB
TypeScript
import { Maybe } from "./maybe";
import { ErrorM } from "./error";
import { Monad } from './monad';
import { Pr } from "../index";
/**
* Class State - it takes a state and returns an intermediate value and some new state value.
* @extends {Monad}
*/
export declare class State<T> extends Monad<T> {
/**
* @type {any}
* @protected
*/
protected state: Pr<T> | Error;
/**
* @type {Maybe}
* @protected
*/
protected maybe: Maybe<T>;
/**
* @type {ErrorM}
* @protected
*/
protected err: ErrorM<T>;
/**
* Creates an instance of the class State with an initialization or not, the initialization can be occur late with bind method.
* @param {Object} [state] - the initial state of app.
*/
constructor(state?: Pr<T> | Error);
/**
* It takes an initial state of the monad if monad has initialized in the constructor then function assigns Error to underlying value.
* @method bind
* @param {Function} f
* @param [v] - underlying value for the monad, it can be null.
*/
bind<T>(f: Function, v?: any): void;
/**
* Changes the state of application variables, if you try add new key with put() to state object it'll be assigned
* with Error instance.
* @method put
* @param {function(v: T)=> T} f - app. state transformation function.
*/
put(f: (v: T) => T): void;
/**
* Extracts the state of app.
* @method get
* @return {Pr<T> | Error}
*/
get(): Pr<T> | Error;
}