alt<L, R> function

Either<L, R> Function(Either<L, R> either) alt<L, R>(
  1. Either<L, R> onLeft(
    1. L left
    )
)

Recieves an Either, and if it is a Left value replaces it with an alternative Either determined by executing the onLeft callback.

expect(
  left('fail').chain(alt((s) => right('caught the $s'))),
  right('caught the fail'),
);
expect(
  right('yay').chain(alt((s) => right('caught the $s'))),
  right('yay'),
);

Implementation

Either<L, R> Function(Either<L, R> either) alt<L, R>(
  Either<L, R> Function(L left) onLeft,
) =>
    fold(onLeft, right);