我想学习F#函数式编程,但我在将一些概念从Javascript函数式编程翻译到F#时遇到了一些问题。我有这段代码可以让我像这样在Javascript中组合函数的“管道”:
这种类型的组合在F#中是否可行?我该怎么做呢?
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
。 - Mulan