Option<T> class
sealed
Option represents the union of two types - Some<T>
and None
.
Constructors
-
Option.new(_OptionEarlyReturnFunction<
T> fn) -
Creates a context for early return, similar to "Do notation". Works like the Rust "?" operator, which is a
"Early Return Operator". Here "$" is used as the "Early Return Key". when "$" is used on a type None,
immediately the context that "$" belongs to is returned with None. e.g.
factory
- Option.of(T? v)
-
Converts from
T?
toOption<T>
.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
and<
U> (Option< U> other) → Option<U> -
Returns None if the option is None, otherwise returns
other
. -
andThen<
U> (Option< U> f(T)) → Option<U> - Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. Some languages call this operation flatmap.
-
copy(
) → Option< T> - Shallow copies this Option
-
expect(
String msg) → T - Returns the contained Some value if Some, otherwise throws a Panic.
-
filter(
bool predicate(T)) → Option< T> - Returns None if the option is None, otherwise calls predicate with the wrapped value and returns Some(t) if predicate returns true (where t is the wrapped value), and
-
flatten(
) → Option< (A, B, C)> -
Available on Option<
Flattens an option into a single tuple.((A, B), C)> , provided by the Option$OptionNestedRecord3Extension extension -
flatten(
) → Option< (A, B, C, D, E)> -
Available on Option<
Flattens an option into a single tuple.((((A, B), C), D), E)> , provided by the Option$OptionNestedRecord5Extension extension -
flatten(
) → Option< T> -
Available on Option<
Converts from Option<OptionOption< , provided by the Option$OptionOptionExtension extensionT> > -
flatten(
) → Option< T> -
Available on Option<
Converts from Option<T?> to OptionT?> , provided by the Option$OptionNullableExtension extension -
flatten(
) → Option< (A, B, C, D)> -
Available on Option<
Flattens an option into a single tuple.(((A, B), C), D)> , provided by the Option$OptionNestedRecord4Extension extension -
inspect(
dynamic f(T)) → Option< T> - Calls the provided closure with a reference to the contained value
-
isNone(
) → bool - Returns true if the option is a None value.
-
isSome(
) → bool - Returns true if the option is a Some value.
-
isSomeAnd(
bool f(T)) → bool - Returns true if the option is a Some and the value inside of it matches a predicate.
-
iter(
) → Iter< T> - Returns an Iter over the possibly contained value.
-
map<
U> (U f(T)) → Option< U> - Maps an this Option
-
mapOr<
U> (U defaultValue, U f(T)) → U - Returns the provided default result (if none), or applies a function to the contained value (if any).
-
mapOrElse<
U> (U defaultFn(), U f(T)) → U - Computes a default function result (if none), or applies a different function to the contained value (if any).
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
okOr<
E extends Object> (E err) → Result< T, E> - Transforms the Option
-
okOrElse<
E extends Object> (E errFn()) → Result< T, E> - Transforms the Option
-
or(
Option< T> other) → Option<T> -
Available on Option<
Returns the option if it contains a value, otherwise returnsT> , provided by the Option$NoneExtension extensionother
-
orElse(
Option< T> f()) → Option<T> -
Available on Option<
Returns the option if it contains a value, otherwise calls f and returns the result.T> , provided by the Option$NoneExtension extension -
toFutureOption(
) → Future< Option< T> > -
Available on Option<
Converts a OptionT> , provided by the Option$ToFutureOptionExtension extension -
toNullable(
) → T? -
toString(
) → String -
A string representation of this object.
inherited
-
transpose(
) → Result< Option< S> , F> -
Available on Option<
Transposes an Option of a Result into a Result of an Option.Result< , provided by the Option$OptionResultExtension extensionS?, F> > -
unwrap(
) → T - Returns the contained Some value, consuming the self value.
-
unwrapOr(
T defaultValue) → T -
Available on Option<
Returns the contained Some value or a provided default.T> , provided by the Option$NoneExtension extension -
unwrapOrElse(
T f()) → T -
Available on Option<
Returns the option if it contains a value, otherwise returns other.T> , provided by the Option$NoneExtension extension -
unzip(
) → (Option< T> , Option<U> ) -
Available on Option<
Unzips an option containing a tuple of two options. If self is Some((a, b)) this method returns (Some(a), Some(b)). Otherwise, (None, None) is returned.(T, U)> , provided by the Option$OptionRecord2Extension extension -
xor(
Option< T> other) → Option<T> -
Available on Option<
Returns Some if exactly one of this orT> , provided by the Option$NoneExtension extensionother
is Some, otherwise returns None. -
zip<
U> (Option< U> other) → Option<(T, U)> - Zips self with another Option.
-
zipWith<
U, R> (Option< U> other, R f(T, U)) → Option<R> - Zips self and another Option with function f
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
_OptionEarlyReturnKey op) → T -
Functions an "Early Return Operator" when given an "Early Return key" "$". See
Option.$
for more information.
Static Methods
-
async<
T> (_OptionAsyncEarlyReturnFunction< T> fn) → Future<Option< T> > - Creates a context for async early return, similar to "Do notation". Works like the Rust "?" operator, which is a "Early Return Operator". Here "$" is used as the "Early Return Key". when "$" is used on a type None, immediately the context that "$" belongs to is returned with None. e.g.