Почему третья функция не вызывается в pipeK, когда все они являются фьючерсами?
Я не могу понять, почему третья функция (т.е. doStuff3
) не вызывается, поэтому 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
1 ответ
Решение
Будущее не сосет как обещание
Сломанный 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
Но люди часто об этом забывают - в будущем таких проблем нет...
Будущее заставляет вас указать путь ошибки, указав в качестве первого параметра - как исполнителя, так и fork
Инг функция
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