Minimal function composition implementation
cumpá
in some Italian 🇮🇹 dialects meansfellow
import compose from 'cumpa'
const add2 = x => x + 2
const multiplyBy3 = x => x * 3
const add2AndMultiplyBy3 = compose(multiplyBy3, add2)
console.log(add2AndMultiplyBy3(1)) // ((1 + 2) * 3) = 9
Similar to compose but performs from left-to-right function composition.
see also
fns
...[function] ) - list of unary fynctionsReturns any result of the computation
Performs right-to-left function composition.
Use Array.prototype.reduce() to perform right-to-left function composition.
The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.
source code
fns
...[function] ) - list of unary fynctionsReturns any result of the computation