state-monad-ts
Version:
state monad in typescript
20 lines (19 loc) • 709 B
TypeScript
export declare type RunState<S, A> = (s: S) => [A, S];
export declare type Unit = null;
export declare const unit: Unit;
export declare class State<S, A> {
readonly [Symbol.toStringTag] = "StateMoand";
runState: RunState<S, A>;
execState: (s: S) => S;
evalState: (s: S) => A;
constructor(runState: RunState<S, A>);
map<B>(f: (p: A) => B): State<S, B>;
static pure<S, A>(a: A): State<S, A>;
ap<B>(fa: State<S, (x: A) => B>): State<S, B>;
static return: typeof State.pure;
bind<B>(f: (a: A) => State<S, B>): State<S, B>;
then: <B>(f: (a: A) => State<S, B>) => State<S, B>;
get(): this;
put(s: S): State<S, null>;
modify(f: (s: S) => S): State<S, null>;
}