jsadvent/lib/fn.js

18 lines
457 B
JavaScript
Raw Normal View History

2020-12-10 08:33:00 +00:00
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);
};
},
};