Ramda,如果条件通过,则在管道中传递值

Ramda, pass value in pipe if condition pass

export const getValueFromPsetProperty = (pset: string, property: string) => R.pipe(
  R.prop('pSets'),
  R.find(R.propEq('name', pset)),
  R.propOr([], 'properties'),
  R.find(R.propEq('name', property)),
  R.propOr(null, 'value'),
  R.ifElse(isValueValid, null,R.identity),
);

最后一个管道不起作用。我想要做的是在 isValueValid 为真时传递该值。我应该怎么做?

您似乎没有正确使用 R.ifElse。所有前三个参数都应该是函数:

  1. 谓词函数
  2. 谓词为真时执行的函数
  3. 谓词为假时执行的函数

因此根据您的描述,如果 isValueValid return 为真,您希望 return 值不变。在这种情况下,您的 R.ifElse 应该是:

R.ifElse(isValueValid, R.identity, someOtherFunction)

您可能需要考虑 R.unless,只有当谓词为假时,它才会 运行 一个函数。如果值有效,则 R.unless return 不变。

R.unless(isValueValid, someFunctionIfValueIsNotValid);