【发布时间】:2018-06-18 10:38:53
【问题描述】:
如何修改zComposedFn函数,使z和zComposedOutput的输出相同?
const R = require('ramda');
let f1 = R.curry((p1, p2, p3) => {
let result = {
n1: p1,
n2: p2,
n3: p3
};
return result;
}
);
let x = f1(1, 2, 3);
let y = f1(1, 2, x);
let z = f1(1, x , y);
console.log(z);
let zComposedFn = R.compose(f1);
let input = [1,2,3];
let zComposedOutput = zComposedFn(...input);
console.log(zComposedOutput);
目标是创建一些具有相同签名和输出类型但实现不同的度量计算函数。
const MetricFn = (m,f,a) => {<to be implemented using switch case on m> return b}
m : name of metric as string
f : Array of functions utilizing input data objects
a : input data object
示例:
有一个财务仪表板,它接收输入数据为 (1,2,3)。 Dashboard 显示 metric1、metric2 和 metric3 计算如下:
metric1 = MetricFn('metric1',[f1])(1,2,3);
metric2 = MetricFn('metric2',[f1, f2])(1,2,3);
metric3 = MetricFn('metric3',[f1, f2, f3])(1,2,3);
我想知道如何创建 MetricFn 的结构。
【问题讨论】:
-
ramdajs.com/docs/#compose 注意:最右边的函数可以有任意数量;其余函数必须是一元的。
-
您能否举例说明
metric3的函数可能是什么样的?我仍然对每个指标的行为方式以及它们如何与f1、f2等相关联感到困惑。
标签: javascript functional-programming ramda.js