为什么当所有函数都是期货时,第三个函数不会在 pipeK 中被调用?

Why the third function doesn't get called in a pipeK when all of them are futures?

我不明白为什么第三个函数(即 doStuff3)没有被调用,所以 fork 上的 console.log 应该打印 "hello world!!!!"

const 
  doStuff = () => Future.of(["hello", "world"]),
  doStuff2 = (x, y) => Future((resolve, reject) => resolve(`${x} ${y}`)),
  doStuff3 = x => Future.of(`${x}!!!!`)

pipeK(doStuff, apply(doStuff2), doStuff3)().fork(console.log, console.error)

您可以 运行 在 Ramda REPL

未来不会像承诺那样糟糕

破损的 Promise API 允许您 then 无需处理错误

 // uh, what happens if there's a problem ?
 myPromise .then (console.log)

 // proper use, but nothing forces you to specify 2nd argument
 myPromise .then (console.log, console.error)

当然可以 .catch,但人们也经常忘记这一点 – Future 没有这些问题...


Future 强制您通过将其作为第一个参数来指定错误路径 – 在执行程序 forking 函数

const f1 = (...xs) =>
  Future.of (xs)

const f2 = (x, y) =>
  Future ((reject, resolve) => // REJECT comes first
    resolve (x + y))

const f3 = x =>
  Future.of (`${x} !!!`)

const myFuture =
  pipeK (f1, apply (f2), f3)
    ("hello", "world")

               // ERROR path first
myFuture.fork (console.error, console.log)
// logs: "helloworld !!!"
// returns: undefined