OptionQuery<T> extension

Reading an Option without matching on it.

const nickname = Some<String>('John');
final hasJohn = nickname.contains('John'); // true
final text = nickname.expect('a nickname was set'); // 'John'
on

Methods

contains(T value) bool

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

Whether this option holds a value equal to value.
expect(String message) → T

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

Returns the present value, or throws message when absent.
isNoneOr(bool predicate(T value)) bool

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

Whether the option is absent, or its value satisfies predicate.
isSomeAnd(bool predicate(T value)) bool

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

Whether a value is present and satisfies predicate.
toIterable() Iterable<T>

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

Returns the present value as a one-element iterable, or an empty one.
toNullable() → T?

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

Returns the present value, or null when absent.
unwrap() → T

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

Returns the present value, or throws when absent.