"use strict"; /** * @since 2.0.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.bindTo_ = exports.bind_ = exports.hole = exports.pipe = exports.untupled = exports.tupled = exports.absurd = exports.decrement = exports.increment = exports.tuple = exports.flow = exports.flip = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.not = exports.unsafeCoerce = exports.identity = void 0; /** * @since 2.0.0 */ function identity(a) { return a; } exports.identity = identity; /** * @since 2.0.0 */ exports.unsafeCoerce = identity; /** * @since 2.0.0 */ function not(predicate) { return function (a) { return !predicate(a); }; } exports.not = not; /** * @since 2.0.0 */ function constant(a) { return function () { return a; }; } exports.constant = constant; /** * A thunk that returns always `true` * * @since 2.0.0 */ exports.constTrue = function () { return true; }; /** * A thunk that returns always `false` * * @since 2.0.0 */ exports.constFalse = function () { return false; }; /** * A thunk that returns always `null` * * @since 2.0.0 */ exports.constNull = function () { return null; }; /** * A thunk that returns always `undefined` * * @since 2.0.0 */ exports.constUndefined = function () { return; }; /** * A thunk that returns always `void` * * @since 2.0.0 */ exports.constVoid = function () { return; }; // TODO: remove in v3 /** * Flips the order of the arguments of a function of two arguments. * * @since 2.0.0 */ function flip(f) { return function (b, a) { return f(a, b); }; } exports.flip = flip; function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) { switch (arguments.length) { case 1: return ab; case 2: return function () { return bc(ab.apply(this, arguments)); }; case 3: return function () { return cd(bc(ab.apply(this, arguments))); }; case 4: return function () { return de(cd(bc(ab.apply(this, arguments)))); }; case 5: return function () { return ef(de(cd(bc(ab.apply(this, arguments))))); }; case 6: return function () { return fg(ef(de(cd(bc(ab.apply(this, arguments)))))); }; case 7: return function () { return gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))); }; case 8: return function () { return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))); }; case 9: return function () { return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))))); }; } return; } exports.flow = flow; /** * @since 2.0.0 */ function tuple() { var t = []; for (var _i = 0; _i < arguments.length; _i++) { t[_i] = arguments[_i]; } return t; } exports.tuple = tuple; /** * @since 2.0.0 */ function increment(n) { return n + 1; } exports.increment = increment; /** * @since 2.0.0 */ function decrement(n) { return n - 1; } exports.decrement = decrement; /** * @since 2.0.0 */ function absurd(_) { throw new Error('Called `absurd` function which should be uncallable'); } exports.absurd = absurd; /** * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument. * * @example * import { tupled } from 'fp-ts/function' * * const add = tupled((x: number, y: number): number => x + y) * * assert.strictEqual(add([1, 2]), 3) * * @since 2.4.0 */ function tupled(f) { return function (a) { return f.apply(void 0, a); }; } exports.tupled = tupled; /** * Inverse function of `tupled` * * @since 2.4.0 */ function untupled(f) { return function () { var a = []; for (var _i = 0; _i < arguments.length; _i++) { a[_i] = arguments[_i]; } return f(a); }; } exports.untupled = untupled; function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr, rs, st) { switch (arguments.length) { case 1: return a; case 2: return ab(a); case 3: return bc(ab(a)); case 4: return cd(bc(ab(a))); case 5: return de(cd(bc(ab(a)))); case 6: return ef(de(cd(bc(ab(a))))); case 7: return fg(ef(de(cd(bc(ab(a)))))); case 8: return gh(fg(ef(de(cd(bc(ab(a))))))); case 9: return hi(gh(fg(ef(de(cd(bc(ab(a)))))))); case 10: return ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))); case 11: return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))); case 12: return kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))); case 13: return lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))); case 14: return mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))); case 15: return no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))); case 16: return op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))); case 17: return pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))); case 18: return qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))))); case 19: return rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))))); case 20: return st(rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))))))); } return; } exports.pipe = pipe; /** * Type hole simulation * * @since 2.7.0 */ exports.hole = absurd; /** * @internal */ exports.bind_ = function (a, name, b) { var _a; return Object.assign({}, a, (_a = {}, _a[name] = b, _a)); }; /** * @internal */ exports.bindTo_ = function (name) { return function (b) { var _a; return (_a = {}, _a[name] = b, _a); }; };