Option<T> class abstract

Option is a type that represents either some value (Some) or none (None).

Option<T> is the type used for returning an optional value. It is an object with a Some value, and None, representing no value.

Implementers

Constructors

Option()
const
Option.from(T? v)
Create a option from a nullable value.
factory
Option.none()
Create a None option with no value.
factory
Option.some(T v)
Create a Some option with the given value.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited

Methods

and(Option<T> optb) Option<T>
Returns None if the option is None, otherwise returns optb.
andThen(Option<T> op(T)) Option<T>
Returns None if the option is None, otherwise calls op with the wrapped value and returns the result.
expect(String msg) → T
Unwraps an option, yielding the content of a Some.
filter(bool predicate(T)) Option<T>
Returns None if the option is None, otherwise calls predicate with the wrapped value and returns:
isNone() bool
Returns true if the option is a None value.
isSome() bool
Returns true if the option is a Some value.
map<U>(U op(T)) Option<U>
Maps an Option<T> to Option<U> by applying a function to a contained Some value. Otherwise returns a None.
mapOr<U>(U op(T), U opt) → U
Applies a function to the contained value (if any), or returns the provided default (if not).
mapOrElse<U>(U op(T), U def()) → U
Maps an Option<T> to U by applying a function to a contained T value, or computes a default (if not).
match<R>(R someop(T), R noneop()) → R
Invokes either the someop or the noneop depending on the option.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
okOr<E>(E err) Result<T, E>
Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).
okOrElse<E>(E err()) Result<T, E>
Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err()).
or(Option<T> optb) Option<T>
Returns the option if it contains a value, otherwise returns optb.
orElse(Option<T> op()) Option<T>
Returns the option if it contains a value, otherwise calls op and returns the result.
toNullable() → T?
Returns an nullable that represents this optional value.
toString() String
A string representation of this object.
inherited
unwrap() → T
Unwraps an option, yielding the content of a Some.
unwrapOr(T opt) → T
Returns the contained value or a default.
unwrapOrElse(T op()) → T
Returns the contained value or computes it from a closure.
when<R>({required R some(T), required R none()}) → R
Invokes either some or none depending on the option.
xor(Option<T> optb) Option<T>
Returns Some if exactly one of this, optb is Some, otherwise returns None.

Operators

operator ==(Object other) bool
The equality operator.
inherited