【发布时间】:2018-04-16 18:46:15
【问题描述】:
我正在尝试学习 F# 函数式编程,但我在将一些概念从 Javascript 函数式编程转换为 F# 时遇到了一些问题。我有这段代码,使我能够像这样在 Javascript 中编写函数的“管道”:
const compose = ((functions) => {
return ((input) => {
return functions.reduce((ack, func) => {
return func(ack);
}, input);
});
});
const addOne = ((input) => input + 1);
const addTwo = ((input) => input + 2);
const composedFunction = compose([addOne, addTwo]);
const result = composedFunction(2);
console.log(result);
甚至可以在 F# 中进行这种组合吗?我该怎么做?
【问题讨论】:
-
你很可能只是想要
let mycomp = f1 >> f2 >> f3 >> f4
标签: javascript f# functional-programming reduce