composeV
Composes variadic functions (n-ary). composeV handles unary functions the same as compose ((x) -> (x) -> (x)) -> (x)
, but can also handle miss-matched arities ((x, y), (x), (x, y, z), ...) -> (x, y, z, ...)
. Composed functions are nested in parameters[0]
while the remaining arguments are passed to parameters[1...]
. This can be useful when you need to compose functions while still being able to pass the same arguments into each successive function unchanged.
Note: composeV is non-curried (compose isn't typically). Be sure to reference ramda or a comparable library to make sure there isn't a better fit out there for your particular use-case.
Install
$ npm install --save compose-v
Usage
const composeV = // Compose unary functionsconst x = x + xconst y = x * xconst xy = // xy :: (a) -> y(x(a)) // 100 OR (5 + 5) * 10 // Compose two binary functionsconst x = x + yconst y = x * yconst xy = // xy :: (a, b) -> y(x(a, b), b) // 50 OR (5 + 5) * 5 // Compose miss-matched n-ary functions// (Must pass maximum arguments, in this case 3)const x = x + yconst y = x * y * zconst xy = // xy :: (a, b, c) -> y(x(a, b, c), b, c) // 24 OR 4 + 6 + 6 + 8
License
MIT © Rob LaFeve