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? to Option<T>.
Option.of(T? v)
Converts from T? to Option<T>.

Properties

v → T?
final
value → T?
no setter

Methods

and<U extends Object>(Option<U> other) Option<U>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns None if the option is None, otherwise returns other.
andThen<U extends Object>(Option<U> f(T)) Option<U>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. Some languages call this operation flatmap.
expect(String msg) → T

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns the contained Some value if Some, otherwise throws a Panic.
filter(bool predicate(T)) Option<T>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

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<((A, B), C)>, provided by the Option$OptionNestedRecord3Extension extension

Flattens an option into a single tuple.
flatten() Option<(A, B, C, D)>

Available on Option<(((A, B), C), D)>, provided by the Option$OptionNestedRecord4Extension extension

Flattens an option into a single tuple.
flatten() Option<(A, B, C, D, E)>

Available on Option<((((A, B), C), D), E)>, provided by the Option$OptionNestedRecord5Extension extension

Flattens an option into a single tuple.
flatten() Option<T>

Available on Option<T?>, provided by the Option$OptionNullableExtension extension

Converts from Option<T?> to Option
flatten() Option<T>

Available on Option<Option<T>>, provided by the Option$OptionOptionExtension extension

Converts from Option<Option
inspect(dynamic f(T)) Option<T>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Calls the provided closure with a reference to the contained value
isNone() bool

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns true if the option is a None value.
isSome() bool

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns true if the option is a Some value.
isSomeAnd(bool f(T)) bool

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns true if the option is a Some and the value inside of it matches a predicate.
iter() Iter<T>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns an Iter over the possibly contained value.
map<U extends Object>(U f(T)) Option<U>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Maps an this Option
mapOr<U>(U defaultValue, U f(T)) → U

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

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

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Computes a default function result (if none), or applies a different function to the contained value (if any).
okOr<E extends Object>(E err) → Result<T, E>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Transforms the Option
okOrElse<E extends Object>(E errFn()) → Result<T, E>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Transforms the Option
or(Option<T> other) Option<T>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns the option if it contains a value, otherwise returns other.
orElse(Option<T> f()) Option<T>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns the option if it contains a value, otherwise calls f and returns the result.
toFutureOption() Future<Option<T>>

Available on Option<T>, provided by the Option$ToFutureOptionExtension extension

Converts a Option
transpose() → Result<Option<S>, F>

Available on Option<Result<S?, F>>, provided by the Option$OptionResultExtension extension

Transposes an Option of a Result into a Result of an Option.
unwrap() → T

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns the contained Some value, consuming the self value.
unwrapOr(T defaultValue) → T

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns the contained Some value or a provided default.
unwrapOrElse(T f()) → T

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns the contained Some value or computes it from a closure.
unzip() → (Option<T>, Option<U>)

Available on Option<(T, U)>, provided by the Option$OptionRecord2Extension extension

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.
xor(Option<T> other) Option<T>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Returns Some if exactly one of self, other is Some, otherwise returns None.
zip<U extends Object>(Option<U> other) Option<(T, U)>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Zips self with another Option.
zipWith<U extends Object, R extends Object>(Option<U> other, R f(T, U)) Option<R>

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

Zips self and another Option with function f

Operators

operator [](_OptionEarlyReturnKey op) → T

Available on Option<T>, provided by the Option$OptionMethodsExtension extension

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.