UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

23 lines (22 loc) 688 B
import { flow } from "fp-ts/function"; const getIsoIso = () => ({ to: I => ({ get: I.to, reverseGet: I.from }), from: I => ({ to: I.get, from: I.reverseGet }), }); export const toIso = (I) => getIsoIso().to(I); export const fromIso = (I) => getIsoIso().from(I); export const reverse = (I) => ({ to: I.from, from: I.to, }); export const deriveSemigroup = (I) => (S) => ({ concat: (x, y) => I.to(S.concat(I.from(x), I.from(y))), }); export const deriveMonoid = (I) => (M) => ({ empty: I.to(M.empty), concat: (x, y) => I.to(M.concat(I.from(x), I.from(y))), }); export const compose = (F) => (G) => ({ to: flow(F.to, G.to), from: flow(G.from, F.from), });