UNPKG

@typed/fp

Version:

Data Structures and Resources for fp-ts

40 lines 998 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.memoize = exports.swapEithers = void 0; const tslib_1 = require("tslib"); /** * @typed/fp/internal is a place for shared code that doesn't belong in the public API * @internal * @since 0.9.2 */ const E = (0, tslib_1.__importStar)(require("fp-ts/Either")); /** * Helpful for creatin ChainRec instances for Either-based types. * @internal * @since 0.9.2 * @category Combinator */ const swapEithers = (either) => { if (E.isLeft(either)) { return E.right(either); } const e = either.right; if (E.isLeft(e)) { return e; } return E.right(e); }; exports.swapEithers = swapEithers; function memoize(f) { const cache = new Map(); return (a) => { if (!cache.has(a)) { const b = f(a); cache.set(a, b); return b; } return cache.get(a); }; } exports.memoize = memoize; //# sourceMappingURL=internal.js.map