Ramda中的布尔返回函数

问题描述 投票:0回答:1

我刚刚开始探索Ramda库,并遇到了一些问题。

假设我们有一个函数,该函数将字符串和字符串列表作为参数,如果给定的字符串在列表中,则返回true。在第4行,我想记录otherList中包含的not中的list中的第一个元素。

const isInList = R.curry((name: string, list: string[]) => list.some(elem => elem === name))
const list = ['a', 'b', 'c']
const otherList = ['a', 'b', 'd', 'c']
console.log(otherList.find(!isInList(R.__, list)))

我找不到会反转给定功能逻辑结果的Ramda函数。

如果存在,它将看起来像这样:

const not = (func: (...args: any) => boolean) => (...args: any) => !func(args)

然后我的目标可以存档为:

console.log(otherList.find(not(isInList(R.__, list)))

功能是否像Ramda中那样存在?

我刚刚开始探索Ramda库,但遇到了一些问题。假设我们有一个函数,该函数将字符串和字符串列表作为参数,如果给定的字符串在列表中,则返回true。 ...

javascript typescript functional-programming ramda.js
1个回答
0
投票

找到了!叫做R.complement()

© www.soinside.com 2019 - 2024. All rights reserved.