使用 Ramda 进行部分应用程序参数操作
Partial application argument manipulation with Ramda
这显然是行不通的——因为 always
不像在 whenPropTrueAlways
的顶级实现中那样用 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(__), __);
在此先感谢您的帮助。
这显然是行不通的——因为 always
不像在 whenPropTrueAlways
的顶级实现中那样用 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(__), __);
在此先感谢您的帮助。