UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

41 lines 1.97 kB
import { IMonad } from "../classes/monad.js"; import { IMonadTrans } from "../classes/transformer.js"; import { $, $B, $Q, KRoot } from "../core/hkt.js"; import { Free } from "./free/free.js"; /** Alias for a constant function. */ export type Lazy<T> = () => T; /** Higher-kinded type for lazy values. */ export interface KLazy extends KRoot { readonly 0: unknown; readonly body: Lazy<this[0]>; } /** The lazy monad. */ export interface ILazy extends IMonad<KLazy> { /** Memoizes the given lazy value. */ memo<A>(f: Lazy<A>): Lazy<A>; /** Creates a lazy value from the given constant function. */ lazy<A>(f: () => A): Lazy<A>; /** Evaluates the given lazy value. */ run<A>(fa: Lazy<A>): A; /** Non-recursively evaluates the given free monad having as its underlying functor the lazy functor. */ runFree<A>(t: Free<A, KLazy>): Lazy<A>; /** Transforms the given monad into a monad transformer where the lazy is the outer monad. */ transformOver<M>(m: IMonad<M>): IMonadTrans<KTransformOver, M>; /** Transforms the given monad into a monad transformer where the lazy is the inner monad. */ transformUnder<M>(m: IMonad<M>): IMonadTrans<KTransformUnder, M>; } /** The lazy monad transformer type where the lazy is the outer monad. */ export type KTransformOver = $<$B, KLazy>; /** The lazy monad transformer type where the lazy is the inner monad. */ export type KTransformUnder = $<$Q, KLazy>; /** The lazy monad transformer where the lazy is the outer monad. */ export interface ITransformOver<M> extends IMonadTrans<KTransformOver, M> { drop<A>(ma: Lazy<$<M, A>>): $<M, A>; } /** The lazy monad transformer where the lazy is the inner monad. */ export interface ITransformUnder<M> extends IMonadTrans<KTransformUnder, M> { drop<A>(ma: $<M, Lazy<A>>): $<M, A>; } /** The lazy monad, providing a set of functions for working with lazy values. */ export declare const lazy: ILazy; //# sourceMappingURL=lazy.d.ts.map