Option<T>
extension type
Option represents the union of two types - Some<T>
and None
. As an extension Option$type of T?
, Option<T>
has the same runtime cost of T?
with the advantage of being able to chain null specific operations.
- on
-
- T?
- Available extensions
Constructors
-
Option(_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.from(T? v)
-
Converts from
T?
toOption<T>
. - Option.of(T? v)
-
Converts from
T?
toOption<T>
.
Methods
-
and<
U extends Object> (Option< U> other) → Option<U> -
Available on Option<
Returns None if the option is None, otherwise returnsT> , provided by the Option$OptionMethodsExtension extensionother
. -
andThen<
U extends Object> (Option< U> f(T)) → Option<U> -
Available on Option<
Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. Some languages call this operation flatmap.T> , provided by the Option$OptionMethodsExtension extension -
expect(
String msg) → T -
Available on Option<
Returns the contained Some value if Some, otherwise throws a Panic.T> , provided by the Option$OptionMethodsExtension extension -
filter(
bool predicate(T)) → Option< T> -
Available on Option<
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), andT> , provided by the Option$OptionMethodsExtension extension -
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)> -
Available on Option<
Flattens an option into a single tuple.(((A, B), C), D)> , provided by the Option$OptionNestedRecord4Extension 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<T?> to OptionT?> , provided by the Option$OptionNullableExtension extension -
flatten(
) → Option< T> -
Available on Option<
Converts from Option<OptionOption< , provided by the Option$OptionOptionExtension extensionT> > -
inspect(
dynamic f(T)) → Option< T> -
Available on Option<
Calls the provided closure with a reference to the contained valueT> , provided by the Option$OptionMethodsExtension extension -
isNone(
) → bool -
Available on Option<
Returns true if the option is a None value.T> , provided by the Option$OptionMethodsExtension extension -
isSome(
) → bool -
Available on Option<
Returns true if the option is a Some value.T> , provided by the Option$OptionMethodsExtension extension -
isSomeAnd(
bool f(T)) → bool -
Available on Option<
Returns true if the option is a Some and the value inside of it matches a predicate.T> , provided by the Option$OptionMethodsExtension extension -
iter(
) → Iter< T> -
Available on Option<
Returns an Iter over the possibly contained value.T> , provided by the Option$OptionMethodsExtension extension -
map<
U extends Object> (U f(T)) → Option< U> -
Available on Option<
Maps an this OptionT> , provided by the Option$OptionMethodsExtension extension -
mapOr<
U> (U defaultValue, U f(T)) → U -
Available on Option<
Returns the provided default result (if none), or applies a function to the contained value (if any).T> , provided by the Option$OptionMethodsExtension extension -
mapOrElse<
U> (U defaultFn(), U f(T)) → U -
Available on Option<
Computes a default function result (if none), or applies a different function to the contained value (if any).T> , provided by the Option$OptionMethodsExtension extension -
okOr<
E extends Object> (E err) → Result< T, E> -
Available on Option<
Transforms the OptionT> , provided by the Option$OptionMethodsExtension extension -
okOrElse<
E extends Object> (E errFn()) → Result< T, E> -
Available on Option<
Transforms the OptionT> , provided by the Option$OptionMethodsExtension extension -
or(
Option< T> other) → Option<T> -
Available on Option<
Returns the option if it contains a value, otherwise returns other.T> , provided by the Option$OptionMethodsExtension extension -
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$OptionMethodsExtension extension -
toFutureOption(
) → Future< Option< T> > -
Available on Option<
Converts a OptionT> , provided by the Option$ToFutureOptionExtension extension -
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 -
Available on Option<
Returns the contained Some value, consuming the self value.T> , provided by the Option$OptionMethodsExtension extension -
unwrapOr(
T defaultValue) → T -
Available on Option<
Returns the contained Some value or a provided default.T> , provided by the Option$OptionMethodsExtension extension -
unwrapOrElse(
T f()) → T -
Available on Option<
Returns the contained Some value or computes it from a closure.T> , provided by the Option$OptionMethodsExtension 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 self,T> , provided by the Option$OptionMethodsExtension extensionother
is Some, otherwise returns None. -
zip<
U extends Object> (Option< U> other) → Option<(T, U)> -
Available on Option<
Zips self with another Option.T> , provided by the Option$OptionMethodsExtension extension -
zipWith<
U extends Object, R extends Object> (Option< U> other, R f(T, U)) → Option<R> -
Available on Option<
Zips self and another Option with function fT> , provided by the Option$OptionMethodsExtension extension
Operators
-
operator [](
_OptionEarlyReturnKey op) → T -
Available on Option<
Functions an "Early Return Operator" when given an "Early Return key" "$". SeeT> , provided by the Option$OptionMethodsExtension extensionOption.$
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.