【发布时间】:2018-04-03 18:25:38
【问题描述】:
见以下代码sn-p:
const
fun1 = () => Either.of(1),
fun2 = () => Either.of(2),
fun3 = () => Either.of(3),
fun4 = curry((x, y, z) => Either.of(x + y + z)),
fun5 = x => Either.of(x + 1),
fun6 = () => pipeK(
() => sequence(Either.of, [fun1(), fun2(), fun3()]),
apply(fun4),
fun5
)(),
result = fun6() // returns 7
fun4 需要 3 个参数,我只想在它们都是 正确 参数的情况下提供它们。也就是说,sequence 将应用每个单子值,因此我会将它们作为单个 right 包含原始的 fun1、fun2、fun3 返回值。
这是推荐的方法吗?
【问题讨论】:
标签: javascript functional-programming monads ramda.js fantasyland