Attaches callbacks for the resolution and/or rejection of the Promise.
A Promise for the completion of which ever callback is executed.
Returns the first Right
between the future value of this
and another EitherAsync
or the Left
in the argument if both this
and the argument resolve to Left
Applies a Right
function wrapped in EitherAsync
over a future Right
value. Returns Left
if either the this
resolves to a Left
or the function is Left
Given two functions, maps the value that the Promise inside this
resolves to using the first if it is Left
or using the second one if it is Right
Structural pattern matching for EitherAsync
in the form of a function
Transforms this
with a function that returns a EitherAsync
. Behaviour is the same as the regular Either#chain
The same as EitherAsync#chain but executes the transformation function only if the value is Left. Useful for recovering from errors
Returns this
if it resolves to a Left
, otherwise it returns the result of applying the function argument to this
and wrapping it in a Right
Runs an effect if this
is Left
, returns this
to make chaining other methods possible
Runs an effect if this
is Right
, returns this
to make chaining other methods possible
Flattens an Either
nested inside an EitherAsync
. e.join()
is equivalent to e.chain(async x => x)
Transforms the Right
value of this
with a given function. If the EitherAsync
that is being mapped resolves to a Left then the mapping function won't be called and run
will resolve the whole thing to that Left, just like the regular Either#map
Maps the Left
value of this
, acts like an identity if this
is Right
It's important to remember how run
will behave because in an
async context there are other ways for a function to fail other
than to return a Nothing, for example:
If any of the computations inside EitherAsync resolved to a Left,
run
will return a Promise resolved to that Left.
If any of the promises were to be rejected then run
will return
a Promise resolved to a Left with the rejection value inside
If an exception is thrown then run
will return a Promise
resolved to a Left with the exception inside
If none of the above happen then a promise resolved to the
returned value wrapped in a Right will be returned
Returns Right
if this
is Left
and vice versa
Converts this
to a MaybeAsync, discarding any error values
Useful if you are not interested in the result of an operation
WARNING: This is implemented only for Promise compatibility. Please use
chain
instead.