toEitherFuture<L> method

Future<Either<L, R>> toEitherFuture<L>(
  1. ErrorMapper<L> errorMapper
)

Transform data value to Right or error value to Left. If this Future completes with a value, returns a Right containing that value. Otherwise, calling errorMapper with the error value and wrap the result in a Left.

Example

final Future<int> f = Future.value(1);
final Future<Either<Object, int>> eitherFuture = f.toEitherFuture((e, s) => e);

eitherFuture.then(print); // prints Either.Right(1)

Implementation

Future<Either<L, R>> toEitherFuture<L>(ErrorMapper<L> errorMapper) =>
    Either.catchFutureError(errorMapper, () => this);