简体   繁体   中英

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM