tap method

Either<L, R> tap(
  1. void f(
    1. R value
    )
)

The given function is applied as a fire and forget effect if this is a Right. When applied the result is ignored and the original Either value is returned.

Example

Right<int, int>(12).tapLeft((_) => println('flower')); // Result: prints 'flower' and returns: Right(12)
Left<int, int>(12).tapLeft((_) => println('flower'));  // Result: Left(12)

Implementation

Either<L, R> tap(void Function(R value) f) {
  if (isRight) {
    f(_unionValue as R);
  }
  return this;
}