UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

26 lines 1.31 kB
import { IFoldBase, IFold } from "./fold.js"; import { IFunctorBase } from "./functor.js"; import { $, $I, $B2, $Q2 } from "../core/hkt.js"; import { IMonadBase, ITrivial } from "./monad.js"; import { TypeClassArg } from "./utilities.js"; /** The minimal definition of a foldable. */ export interface IFoldableBase<F> extends IFunctorBase<F> { /** Folds the values of `fa` using the given function and initial value. */ foldl<A, B>(f: (b: B, a: A) => B): (b: B) => (fa: $<F, A>) => B; } /** The foldable interface, where `scalar` is the trivial (identity) monad. */ export interface IFoldable<F> extends IFoldableBase<F>, IFold<F, $I> { /** The trivial (identity) monad. */ readonly scalar: ITrivial; /** Lifts a fold over the given monad. */ liftFoldOver<M>(m: IMonadBase<M>): IFold<$B2<F, M>, M>; /** Lifts a fold under the given monad. */ liftFoldUnder<M>(m: IMonadBase<M>): IFold<$Q2<F, M>, M>; /** Nests a fold within another fold. */ nestFold<M, N>(m: IFoldBase<M, N>): IFold<$B2<F, M>, N>; } declare const is_foldable: unique symbol; /** Creates an `IFoldable` from an `IFoldableBase`. */ export declare function foldable<F>(base: TypeClassArg<IFoldableBase<F>, IFoldable<F>, typeof is_foldable>): IFoldable<F>; export {}; //# sourceMappingURL=foldable.d.ts.map