OptionCombine<T> extension

Combining Option values, and moving between Option and Result.

final both = const Some<int>(1).zip(const Some<String>('a')); // Some((1, a))
final checked = const None<int>().okOr('missing'); // Err(missing)
on

Methods

okOr<E>(E error) Result<T, E>

Available on Option<T>, provided by the OptionCombine extension

Returns Ok with a present value, or Err with error when absent.
okOrElse<E>(E error()) Result<T, E>

Available on Option<T>, provided by the OptionCombine extension

Returns Ok with a present value, or computes an Err when absent.
zip<U>(Option<U> other) Option<(T, U)>

Available on Option<T>, provided by the OptionCombine extension

Pairs this value with other's, when both are present.
zipWith<U, R>(Option<U> other, R combine(T left, U right)) Option<R>

Available on Option<T>, provided by the OptionCombine extension

Combines this value with other's, when both are present.