OptionOps<A>
extension OptionOps<A> on Option<A>Properties
get extension no setter
A get getReturns the value if this is a Some, or throws a StateError if this is a None.
This is an unsafe, partial operation. Prefer getOrElse, fold, or pattern matching when the Option may be None. Use get only when you have already proven that this Option is non-empty.
See also getOrNull for a nullable alternative, and getOrElse for providing a fallback value.
Available on Option<A>, provided by the OptionOps<A> extension
Implementation
A get get => fold(() => throw StateError('None.get'), identity);getOrNull extension no setter
A? get getOrNullReturns the value if this is a Some, or null if this is a None.
This is equivalent to Option.toNullable and is provided as a conventionally named companion to get.
Available on Option<A>, provided by the OptionOps<A> extension
Implementation
A? get getOrNull => toNullable();Methods
contains() extension
bool contains(A elem)Available on Option<A>, provided by the OptionOps<A> extension
Implementation
bool contains(A elem) => fold(() => false, (value) => value == elem);getOrElse() extension
A getOrElse(A Function() ifEmpty)Returns the value if this is a Some or the value returned from evaluating ifEmpty.
Available on Option<A>, provided by the OptionOps<A> extension
Implementation
A getOrElse(Function0<A> ifEmpty) => fold(ifEmpty, identity);orElse() extension
If this is a Some, this is returned, otherwise the result of evaluating orElse is returned.
Available on Option<A>, provided by the OptionOps<A> extension
Implementation
Option<A> orElse(Function0<Option<A>> orElse) => fold(orElse, (_) => this);