Я не могу понять, почему третья функция (т. doStuff3
) не вызывается, поэтому console.log
на 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)
Будущее не сосать, как обещание
Разбитый Promise API позволяет then
без обработки ошибок
// uh, what happens if there 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
resolve
первой ...: D Во всяком случае, спасибо за разъяснение :)