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.
38 lines (37 loc) • 1.22 kB
TypeScript
import { M } from "./interfaces/m";
import { MF } from "./types/mf";
import { Pr } from "./types/pr";
import { D } from './types/d';
/**
* Class Monad - Base abstract class.
* @implements {M}
* @abstract
*/
export declare abstract class Monad<T> implements M<T> {
/**
* Binds transformation function and underlying value to the monad.
* @method bind
* @param {MF<T, U> | D<T>} f - transformation function.
* @param v - underlying value.
* @return {Promise<U> | Pr<U> | Error | boolean | void}
* @abstract
*/
abstract bind<T, U>(f: MF<T, U> | D<T>, v: any): Promise<U> | Pr<U> | Error | boolean | void;
/**
* Takes Error or string return Error.
* @method fail
* @param {Error | string} e - Error obj. or string.
* @return {Error}
* @protected
*/
fail(e: Error | string): Error;
/**
* Produces result after execution f(v).
* @method just
* @param {function(v: T) => Pr<U>} f - transformation function for a monad.
* @param {T} v - underlying value.
* @return {Pr<U>} extracts transformed value by f(v).
* @protected
*/
just<T, U>(f: MF<T, U>, v: T): Pr<U>;
}