Yairopro
Yairopro

Reputation: 10324

Is there a function to apply a list of functions to a list of values in Ramda?

Let's call the function f().

Examples

f([dec, identity, inc], [3, 2, 1]) // [2, 2, 2]
f([() => 1, append(3)], [[1, 2], [1, 2]]) // [1, [1, 2, 3]]
f([Number, String], ["2"]) // [2, "undefined"]

I am no asking an implementation of f(), either by writing or composing it with others Ramda functions. I am just asking if such a function already exists in the library and if so, what's its name.

Upvotes: 0

Views: 80

Answers (1)

customcommander
customcommander

Reputation: 18891

juxt is close but not exactly what you need:

juxt([f, g, h], 1, 2, 3)
//=> [f(1, 2, 3), g(1, 2, 3), h(1, 2, 3)]

In your case you want zipWith:

zipWith(call, [dec, identity, inc], [3, 2, 1])
//=> [2, 2, 2]

Upvotes: 3

Related Questions