UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

32 lines (31 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.compose = exports.deriveMonoid = exports.deriveSemigroup = exports.reverse = exports.fromIso = exports.toIso = void 0; const function_1 = require("fp-ts/function"); const getIsoIso = () => ({ to: I => ({ get: I.to, reverseGet: I.from }), from: I => ({ to: I.get, from: I.reverseGet }), }); const toIso = (I) => getIsoIso().to(I); exports.toIso = toIso; const fromIso = (I) => getIsoIso().from(I); exports.fromIso = fromIso; const reverse = (I) => ({ to: I.from, from: I.to, }); exports.reverse = reverse; const deriveSemigroup = (I) => (S) => ({ concat: (x, y) => I.to(S.concat(I.from(x), I.from(y))), }); exports.deriveSemigroup = deriveSemigroup; const deriveMonoid = (I) => (M) => ({ empty: I.to(M.empty), concat: (x, y) => I.to(M.concat(I.from(x), I.from(y))), }); exports.deriveMonoid = deriveMonoid; const compose = (F) => (G) => ({ to: (0, function_1.flow)(F.to, G.to), from: (0, function_1.flow)(G.from, F.from), }); exports.compose = compose;