UNPKG

@fpjs/overture

Version:
38 lines (37 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.min = exports.max = exports.lte = exports.lt = exports.isOrd = exports.gte = exports.gt = exports.clamp = void 0; var _base = require("@fpjs/overture/base"); const isOrd = x => (0, _base.isPrimitive)(x) || "fantasy-land/lte" in x; exports.isOrd = isOrd; const lte = x => y => { if ((0, _base.isPrimitive)(x)) { return x <= y; } const op = x["fantasy-land/lte"]; if (op === undefined) { throw TypeError(`'${(0, _base.type)(x)}' is not an Ord.`); } return x === y || op.call(x, y); }; exports.lte = lte; const lt = x => y => { return !lte(y)(x); }; exports.lt = lt; const gte = x => y => { return lte(y)(x); }; exports.gte = gte; const gt = x => y => { return !lte(x)(y); }; exports.gt = gt; const min = x => y => gt(x)(y) ? y : x; exports.min = min; const max = x => y => gt(x)(y) ? x : y; exports.max = max; const clamp = mn => mx => val => max(mn)(min(mx)(val)); exports.clamp = clamp;