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 = require('compose-v')
const x = x => x + x
const y = x => x * x
const xy = composeV(y, x)
xy(5)
const x = (x, y) => x + y
const y = (x, y) => x * y
const xy = composeV(y, x)
xy(5, 5)
const x = (x, y) => x + y
const y = (x, y, z) => x * y * z
const xy = composeV(y, x)
xy(4, 6, 8)
License
MIT © Rob LaFeve