/** * @typed/fp/internal is a place for shared code that doesn't belong in the public API * @internal * @since 0.9.2 */ import * as E from 'fp-ts/Either' /** * Helpful for creatin ChainRec instances for Either-based types. * @internal * @since 0.9.2 * @category Combinator */ export const swapEithers = ( either: E.Either>, ): E.Either> => { if (E.isLeft(either)) { return E.right(either) } const e = either.right if (E.isLeft(e)) { return e } return E.right(e) } export function memoize(f: (a: A) => B): (a: A) => B { const cache = new Map() return (a) => { if (!cache.has(a)) { const b = f(a) cache.set(a, b) return b } return cache.get(a) } } export type UndoPartial = [A] extends [Partial] ? R : never