moy-fp
Version:
A functional programming library.
12 lines (9 loc) • 360 B
JavaScript
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