toEitherStream<L> method

Stream<Either<L, R>> toEitherStream<L>(
  1. ErrorMapper<L> errorMapper
)

Transform data events to Rights and error events to Lefts.

When the source stream emits a data event, the result stream will emit a Right wrapping that data event.

When the source stream emits a error event, calling errorMapper with that error and the result stream will emits a Left wrapping the result.

The done events will be forwarded.

Example

final Stream<int> s = Stream.fromIterable([1, 2, 3, 4]);
final Stream<Either<Object, int>> eitherStream = s.toEitherStream((e, s) => e);

eitherStream.listen(print); // prints Either.Right(1), Either.Right(2),
                            // Either.Right(3), Either.Right(4),

Implementation

Stream<Either<L, R>> toEitherStream<L>(ErrorMapper<L> errorMapper) =>
    Either.catchStreamError<L, R>(errorMapper, this);