UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

30 lines 1.51 kB
import { $, $I, KRoot } from "../core/hkt.js"; import { IMonad } from "../classes/monad.js"; import { ITransformer } from "../classes/transformer.js"; /** The state monad transformer value type, representing a function that takes a state and returns a new state and a value wrapped in the given type `F`. */ export type StateTrans<F, S, T> = (a: S) => $<F, [T, S]>; /** The state monad value type. */ export type State<S, T> = StateTrans<$I, S, T>; /** Higher-kinded type of the state monad. */ export interface KState<S> extends KRoot { readonly 0: unknown; readonly body: State<S, this[0]>; } /** Higher-kinded type of the state monad transformer. */ export interface KStateTrans<S> extends KRoot { readonly 0: unknown; readonly 1: unknown; readonly body: StateTrans<this[0], S, this[1]>; } /** The state interface, providing stateful computations. */ export interface IState<S> extends IMonad<KState<S>>, ITransformer<KStateTrans<S>> { /** Produces a state that evaluates to the current state. */ readonly get: State<S, S>; /** Produces a state that evaluates to the given value. */ put<S>(s: S): State<S, null>; /** Creates a `state` module with a fixed environment type. */ of<T>(): IState<T>; } /** The `state` module, providing a set of functions for working with state functions. The environment type is fixed to `any`. To change the environment type, call the `of` function. */ export declare const state: IState<any>; //# sourceMappingURL=state.d.ts.map