getOrElse<L, R> function

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

Unwraps an Either. If it is a Right value, then it returns the unwrapped value. If it is a Left, then the onLeft callback determines the fallback.

expect(
  right('hello').chain(getOrElse((left) => 'fallback')),
  'hello',
);
expect(
  left('fail').chain(getOrElse((left) => 'fallback')),
  'fallback',
);

Implementation

R Function(Either<L, R> either) getOrElse<L, R>(
  R Function(L left) onLeft,
) =>
    fold(onLeft, identity);