Option<T> class sealed

Option represents the union of two types - Some<T> and None.

Available extensions

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

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

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

Converts from Option<T?> to Option
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.
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<T>, provided by the Option$NoneExtension 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$NoneExtension 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
toNullable() → T?
toString() String
A string representation of this object.
inherited
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
Returns the contained Some value, consuming the self value.
unwrapOr(T defaultValue) → T

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

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

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

Returns the option if it contains a value, otherwise returns other.
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$NoneExtension extension

Returns Some if exactly one of this or other 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.