javascript - 我应该如何将 Lodash 过滤器方法重写为 Ramda 过滤器?
问题描述
类型 HorizontalLines = Array < ReactTestInstance >
const horizontalLines = _.filter(lines, {props: {height: '1'}});
解决方案
Ramda 的函数往往具有比 lodash 更简单的签名。没有多少地方可以像这个 lodash 函数那样传递函数或对象来配置函数。但是有很多方法可以做到这一点。你只需要结合更多 Ramda 的原始函数。
以下是两个应该有效的解决方案:
filter(pathEq(['props', 'height'], '1'), lines)
filter(where({props: whereEq({height: '1'})}), lines)