UNPKG

@unsplash/sum-types-fp-ts

Version:
40 lines (39 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getShow = exports.getOrd = exports.getEq = void 0; const Sum = require("@unsplash/sum-types"); const Eq_1 = require("fp-ts/Eq"); const Ord_1 = require("fp-ts/Ord"); const string_1 = require("fp-ts/string"); const getEq = (eqs) => (0, Eq_1.fromEquals)((x, y) => { const [xk, xv] = Sum.serialize(x); const [yk, yv] = Sum.serialize(y); if (xk !== yk) return false; const eq = eqs[xk]; return (eq === undefined || eq.equals(xv, yv)); }); exports.getEq = getEq; const getOrd = (ords) => (0, Ord_1.fromCompare)((x, y) => { const [xk, xv] = Sum.serialize(x); const [yk, yv] = Sum.serialize(y); if (xk !== yk) return string_1.Ord.compare(xk, yk); const ord = ords[xk]; return ord === undefined ? 0 : ord.compare(xv, yv); }); exports.getOrd = getOrd; const getShow = (shows) => ({ show: x => { const [k, v] = Sum.serialize(x); return k in shows ? `${k}(${shows[k] .show(v)})` : k; }, }); exports.getShow = getShow;