maybe-monade
Version:
Maybe monad implementation in Typescript
35 lines (34 loc) • 1.31 kB
TypeScript
import { Maybe } from "./maybe";
export declare type f<R> = (...args: any[]) => R;
export declare class MaybeCallback<T> {
private callback;
private constructor();
/**
* return an instance of Maybe wrapping an empty value
*/
static none<R>(): MaybeCallback<R>;
/**
* if the provided callback is not a function, return an instance of Maybe wrapping a nonempty value,
* otherwise throw an error
* @param callback
*/
static some<R>(callback: f<R>): MaybeCallback<R>;
/**
* return true if the wrapped value is empty, false otherwise
*/
isEmpty(): boolean;
/**
* Call the wrapped function in unsafe mode (could throw errors)
* if the wrapped function is empty return empty Maybe,
* otherwise return an instance of Maybe wrapping the function result
* @param args : arguments to pass to the wrapped function
*/
apply(...args: any[]): Maybe<T>;
/**
* call the wrapped function in a safe mode,
* wrap the execution in a try catch bloc. in case of error return empty Maybe,
* otherwise return an instance of Maybe wrapping the function result
* @param args : arguments to pass to the wrapped function
*/
applySafe(...args: any[]): Maybe<T>;
}