flatMapEitherSingle<R2> method

Single<Either<L, R2>> flatMapEitherSingle<R2>(
  1. Single<Either<L, R2>> transform(
    1. R1 value
    )
)

flatMap the Either in the Single context.

When this Single emits a Right value, calling transform callback with Right.value. And returns a new Single which emits the result of the call to transform.

If this Single emits a Left value, returns a Single that emits a Left which containing original Left.value.

This operator does not handle any errors. See flatMapSingle.

Example

Single.value(1.right<String>())
    .flatMapEitherSingle((v) => Single.value(v.toString().right<String>()))
    .listen(print); // Prints Either.Right(1)

Single.value(2.left<String>())
    .flatMapEitherSingle((v) => Single.value(v.toString().right<int>()))
    .listen(print); // Prints Either.Left(2)

Implementation

Single<Either<L, R2>> flatMapEitherSingle<R2>(
  Single<Either<L, R2>> Function(R1 value) transform,
) =>
    flatMapSingle(
      (either) => either.fold(
        ifLeft: (v) => Single.value(v.left<R2>()),
        ifRight: transform,
      ),
    );