admin管理员组文章数量:1201993
How would I best create this function in Ramda?
function get_list (value) {
return [
first_transform(value),
second_transform(value)
]
}
get_list(12)
I guess this is the inverse of the map function.
How would I best create this function in Ramda?
function get_list (value) {
return [
first_transform(value),
second_transform(value)
]
}
get_list(12)
I guess this is the inverse of the map function.
Share Improve this question asked Dec 28, 2015 at 4:59 MattMSMattMS 1,1561 gold badge16 silver badges32 bronze badges1 Answer
Reset to default 27You've got a few options for this.
Assuming your functions are already in a list:
transforms = [first_transform, second_transform];
The first option is to use R.juxt
, which does pretty much exactly what you're after by creating a new function that applies the list of given functions to the values received by the new function.
get_list = R.juxt(transforms);
Another option is R.ap
, which applies a list of functions to a list of values. R.of
can be used to wrap the value in an array.
get_list = R.compose(R.ap(transforms), R.of);
Or lastly, R.map
could be used to receive each function in the list and return the result of applying it to the value.
get_list = value => R.map(fn => fn(value), transforms);
本文标签: javascriptApply a list of functions to a value in RamdaStack Overflow
版权声明:本文标题:javascript - Apply a list of functions to a value in Ramda - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738643680a2104457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论