getOrElse<T> function

T Function(Option<T> option) getOrElse<T>(
  1. Lazy<T> orElse
)

Unwrap the Option's value if it is Some, otherwise it calls the orElse function to determine the fallback value.

expect(
  some('hello').chain(getOrElse(() => 'fallback')),
  'hello',
);
expect(
  none().chain(getOrElse(() => 'fallback')),
  'fallback',
);

Implementation

T Function(Option<T> option) getOrElse<T>(Lazy<T> orElse) =>
    fold(orElse, identity);