Skip to content

When to use the rejection branch #469

Answered by Avaq
quanganhtran asked this question in Q&A
Discussion options

You must be logged in to vote

It looks like Future a b is similar to IO[Either[B, A]] instead of just IO[A],

That's right. You can think of a Future as being IO + Either + Async/Cont.

when should I use Future rejection instead of my own Either (or Result etc.)

The simplest answer to this is: when you want to.

Fluture "mixes in" the Either type for two reasons:

  1. Because in JavaScript, when we're dealing with Async IO, we're usually already dealing with potential failure. And so it'd be very common to have Futures with Eithers inside. It's just more convenient to have it already be part of the type to lower the amount of type juggling you have to do.
  2. Because Fluture is originally meant to be an alternative to Promis…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@quanganhtran
Comment options

@Avaq
Comment options

Answer selected by quanganhtran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants