/** * simple utils around functions, e.g. pipeline helpers * * @module */ export const identity = (value: T) => value; export const iife = (fn: () => T) => fn(); export const ignore = () => {}; export const failWith = (e: unknown) => { throw e; }; export const memoize = ( getKey: (value: Arg) => string, fn: (value: Arg) => T, ) => { const cache = new Map(); return (arg: Arg) => { const key = getKey(arg); if (cache.has(key)) { return cache.get(key)!; } const computed = fn(arg); cache.set(key, computed); return computed; }; };