OptionTransform<T> extension

Transforming and choosing between Option values.

final label = const Some<int>(3).mapOr('none', (count) => '$count items');
final chosen = const None<int>().or(const Some<int>(1)); // Some(1)
on

Methods

and<R>(Option<R> other) Option<R>

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

Returns other when this option is present, and None otherwise.
filter(bool predicate(T value)) Option<T>

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

Keeps a present value only when it satisfies predicate.
inspect(void action(T value)) Option<T>

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

Calls action with a present value, and returns this option unchanged.
mapOr<R>(R fallback, R mapper(T value)) → R

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

Maps a present value, or returns fallback when absent.
mapOrElse<R>(R fallback(), R mapper(T value)) → R

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

Maps a present value, or computes a fallback when absent.
or(Option<T> other) Option<T>

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

Returns this option when present, and other otherwise.
orElse(Option<T> fallback()) Option<T>

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

Returns this option when present, and computes one otherwise.
xor(Option<T> other) Option<T>

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

Returns whichever of the two options is present, when exactly one is.