@jsoldi/hkt
Version:
Higher kinded types for typescript and a few utility monads.
26 lines • 1.35 kB
TypeScript
import { KRoot, $, $B } from "../core/hkt.js";
import { IMonad } from "../classes/monad.js";
import { ITransformer } from "../classes/transformer.js";
/** Alias for a reader function. */
export type Reader<in E, out R> = (a: E) => R;
/** Higher-kinded type for reader functions. */
export interface KReader<E> extends KRoot {
readonly 0: unknown;
readonly body: Reader<E, this[0]>;
}
/** The reader monad transformer type. */
export type KReaderTrans<E> = $<$B, KReader<E>>;
/** The reader interface with fixed environment type, providing a set of functions for working with reader functions. */
export interface IReader<E> extends IMonad<KReader<E>>, ITransformer<KReaderTrans<E>> {
/** Returns a reader that returns the environment. */
readonly ask: Reader<E, E>;
/** Applies a function to the environment. */
local<A>(f: (e: E) => E): (m: Reader<E, A>) => Reader<E, A>;
/** Creates a reader from a function. */
reader<A>(f: (e: E) => A): Reader<E, A>;
/** Creates a `reader` module with a fixed environment type. */
of<T>(): IReader<T>;
}
/** The `reader` module, providing a set of functions for working with reader functions. The environment type is fixed to `any`. To change the environment type, call the `of` function. */
export declare const reader: IReader<any>;
//# sourceMappingURL=reader.d.ts.map