简体   繁体   English

使用 Ramda 将函数列表应用于 arguments 列表

[英]Applying a list of functions to a list of arguments using Ramda

Is there a function in Ramda to apply a list of functions to a list of arguments similar to juxt() but where each function only gets supplied with the argument at the corresponding index in the list of arguments? Is there a function in Ramda to apply a list of functions to a list of arguments similar to juxt() but where each function only gets supplied with the argument at the corresponding index in the list of arguments? Something similar to:类似于:

pipe(zip, map(([a, b]) => a(b)))([func1, func2], ['arg1', 'arg2']);

Is there a better way to do this?有一个更好的方法吗?

Use R.zipWith which creates a new list out of the two supplied by applying the function to each equally-positioned pair in the lists.使用 R.zipWith 从提供的两个列表中创建一个新列表,方法是将 function 应用于列表中每个相同位置的对。

You can also replace the callback with R.call, which invokes the first argument, and passes the rest as it's parameters.您还可以将回调替换为 R.call,它调用第一个参数,并将 rest 作为参数传递。

 const { zipWith, call } = R; const fn = zipWith(call); const func1 = R.add(1); const func2 = R.add(2); const result = fn([func1, func2], [1, 2]); console.log(result);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js" integrity="sha512-rZHvUXcc1zWKsxm7rJ8lVQuIr1oOmm7cShlvpV0gWf0RvbcJN6x96al/Rp2L2BI4a4ZkT2/YfVe/8YvB2UHzQw==" crossorigin="anonymous"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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