jsadvent/lib/fn.js
2020-12-10 02:33:00 -06:00

18 lines
457 B
JavaScript

require('./_pollute/map');
module.exports = {
curry: (fn) => (...args) => (...callArgs) => fn(...[...args, ...callArgs]),
curryRight: (fn) => (...args) => (...callArgs) =>
fn(...[...callArgs, ...args]),
memo: (fn) => {
const memo = new Map();
return (...args) => {
const path = [args.length, ...args];
if (!memo.hasPath(path)) {
memo.setPath(path, fn(...args));
}
return memo.getPath(path);
};
},
};