UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

34 lines 1.19 kB
import { monad } from "../classes/monad.js"; import { monadTrans } from "../classes/transformer.js"; import { id } from "../core/utils.js"; /** Creates a reader having a fixed environment type. */ function readerOf() { const ask = id; const local = (f) => (m) => e => m(f(e)); const _reader = id; const of = () => readerOf(); const transform = (inner) => { return monadTrans({ map: (fa, f) => e => inner.map(fa(e), f), unit: (a) => _ => inner.unit(a), bind: (fa, f) => e => inner.bind(fa(e), a => f(a)(e)), lift: (a) => _ => a, wrap: r => e => inner.unit(r(e)) }); }; return { ...monad({ map: (fa, f) => e => f(fa(e)), unit: (a) => (_) => a, bind: (fa, f) => (e) => f(fa(e))(e) }), ask, local, reader: _reader, of, transform, }; } /** 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 const reader = readerOf(); //# sourceMappingURL=reader.js.map