1

我不知道为什么doStuff3没有调用第三个函数(即),所以console.logon fork 应该打印"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上运行它

4

1 回答 1

1

未来并不像 Promise 那样糟糕

损坏的 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 通过在 executor和fork'ing 函数中设置第一个参数来强制您指定错误路径

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
于 2017-10-19T17:08:25.090 回答