UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

29 lines 1.01 kB
import { functor } from "../classes/functor.js"; import { monoid } from "../classes/monoid.js"; /** Creates a tuple module with a fixed left type. */ function tupleOf() { const of = () => tupleOf(); const _monoid = (l, r) => monoid({ empty: () => [l.empty(), r.empty()], append: ([a1, b1], [a2, b2]) => [l.append(a1, a2), r.append(b1, b2)], }); const map = ([a, b], f) => [a, f(b)]; const swap = ([a, b]) => [b, a]; const left = ([a, _]) => a; const right = ([_, b]) => b; const bimap = ([a, b], f, g) => [f(a), g(b)]; const bifmap = (f, g) => ([a, b]) => [f(a), g(b)]; return { of, monoid: _monoid, swap, left, right, bimap, bifmap, ...functor({ map }), }; } /** The tuple module, providing functions for working with tuple values. The left type is fixed to `any`. To change the left type, call the `of` function. */ export const tuple = tupleOf(); //# sourceMappingURL=tuple.js.map