如何检查 Ramda 中不同的道具是否相等?

How to check if different props are equal in Ramda?

我将如何检查 first 和 last 在这里是否相等?

const obj = {
    first: 5,
    last: 5,
}

这是一个更大问题的一小部分,我将其粘贴在这里只是为了后代:

[
    { first: 5, last: 5, things: [{id: null, item: null} ] },
    { first: 10, last: 15, things:[
        {id: null, item: 10}, {id: null, item: 13}, {id: null, item: 14} 
    ]}
]

基本上我需要将这些数据提炼成这样:

[[5], [10,13,14]]

基本上,要做到这一点,我需要一些条件逻辑,或者查看顶级对象是否具有 null 项,或者(看起来更容易)如果 first 和 last 相等。如果 first 和 last 相等,则获取它们的任何数字,否则映射 "things" 和 return 项目。

必须跳过几圈才能获得积分!在实际场景中拆分成更小的功能肯定也会受益。

map(
   ifElse(
     compose(apply(equals), props(['first', 'last'])),
     compose(of, prop('first')),
     compose(pluck('item'), prop('things'))
   )
 )(input)

刚看到这个,我知道它很旧,但仍然有用。

现在使用 converge 函数可以更轻松地处理等效性测试:

converge(equals, [prop('first'), prop('last')])

要实现 2 个道具的通用相等性,您可以这样做:

const propsEq = R.compose(R.apply(R.equals), R.props)

虽然这会导致非柯里化函数(您必须同时提供包含 2 个要测试的道具和对象的数组)。 我相信有更好的方法...