Functional programming 使用Ramda进行部分应用程序参数操作
这显然不起作用-因为Functional programming 使用Ramda进行部分应用程序参数操作,functional-programming,ramda.js,Functional Programming,Ramda.js,这显然不起作用-因为总是不会像在WhenPropTrueAllways的顶级实现中那样使用whenTrueValue调用。有没有办法像我尝试的那样操纵调用另一个方法?用一个特定值替换一个参数,以及将一个函数应用于另一个参数 export const whenPropEq = curry((key, predicateValue, whenTrueFn, data) => when( propEq(key, predicateValue), whenTrueFn, )
总是不会像在WhenPropTrueAllways
的顶级实现中那样使用whenTrueValue
调用。有没有办法像我尝试的那样操纵调用另一个方法?用一个特定值替换一个参数,以及将一个函数应用于另一个参数
export const whenPropEq = curry((key, predicateValue, whenTrueFn, data) =>
when(
propEq(key, predicateValue),
whenTrueFn,
)(data),
);
const whenPropTrueAlways = curry((key, whenTrueValue, data) =>
whenPropEq(key, true, always(whenTrueValue), data),
);
// Doesn't work, for obvious reasons- just trying to illustrate the desire
const whenPropTrueAlways = whenPropEq(__, true, always(__), __);
提前感谢您的帮助。这并不漂亮,但您可以这样写:
const whenPropTrue = useWith(flip(whenPropEq)(true), [identity, always, identity]);
是一个更不寻常的Ramda函数(以及它的姐妹函数)。它可以帮助你做一些没有分数的事情,否则可能很难做到。但我经常发现,当很难让事情变得自由时,这表明人们不应该费心这么做 谢谢你的回复!我承认我还不熟悉useWith
或converge
——我会深入研究一下。所以在这种特殊情况下,你是说你不会费心去尝试使部分应用程序方法无点吗?我不知道。这不是我的事。我认为您需要问问自己,看看这样一个无点数的解决方案和原始的定点解决方案,在一年后重新打开它时,您(或其他维护代码的人)会更好地理解哪一个。再次感谢您的帮助!