UNPKG

moy-fp

Version:
12 lines (9 loc) 360 B
import curry from './curry' import nAry from './nAry' /** * [(x1, x2, ...) -> a, (x1, x2, ...) -> b, ..., (x1, x2, ...) -> m] -> ((a, b, ..., m) -> n) -> ((x1, x2, ...) -> n) */ const converge = curry( (fns, after) => nAry(fns.reduce((acc, fn) => Math.max(acc, fn.length), 0), (...args) => after(...fns.map(fn => fn(...args)))) ) export default converge