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

40 views Asked by At

I can't figure out why the third function (i.e. doStuff3) isn't being called, so the console.log on fork should print "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)

You can run it on Ramda REPL

1

There are 1 answers

1
Mulan On BEST ANSWER

Future doesn't suck like Promise

The broken Promise API allows you to then without handling errors

 // 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)

Of course you could .catch, but people often forget about that too – Future doesn't have these problems ...


Future forces you to specify the error path by making that the first parameter – in both the executor and the fork'ing function

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