UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

22 lines 867 B
import { pipe } from "../../core/utils.js"; import { either } from "../either.js"; import { contMonad } from "./contMonad.js"; /** Creates a continuation monad where results are wrapped in a free monad given a free monad based on a functor. */ export function contFunctorFree(m) { return pipe(contMonad(m), base => { const suspend = f => resolve => m.suspend(m.freeBase.map(f, ct => ct(resolve))); const delay = fa => resolve => m.suspend(m.freeBase.map(fa, resolve)); const mapFree = (transform) => base.mapCont(either.left, (fg) => m.flat(m.mapFreeFrom(caca => { const rete = transform(caca); return rete; })(fg))); return { ...base, contMonad: m, suspend, delay, mapFree, }; }); } //# sourceMappingURL=contFunctorFree.js.map