alt<T> function

Option<T> Function(Option<T> option) alt<T>(
  1. Lazy<Option<T>> f
)

If the Option is a None, then the result of the given function will determine the [alt]ernate / replacement Option.

If it was Some, then it does nothing.

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

Implementation

Option<T> Function(Option<T> option) alt<T>(Lazy<Option<T>> f) =>
    (option) => isNone(option) ? f() : option;