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.
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 isNone
, otherwise returnsoptb
. -
andThen(
Option< T> op(T)) → Option<T> -
Returns
None
if the option isNone
, otherwise callsop
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 isNone
, otherwise callspredicate
with the wrapped value and returns: -
isNone(
) → bool -
Returns
true
if the option is aNone
value. -
isSome(
) → bool -
Returns
true
if the option is aSome
value. -
map<
U> (U op(T)) → Option< U> -
Maps an
Option<T>
toOption<U>
by applying a function to a containedSome
value. Otherwise returns aNone
. -
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>
toU
by applying a function to a containedT
value, or computes a default (if not). -
match<
R> (R someop(T), R noneop()) → R -
Invokes either the
someop
or thenoneop
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 aResult<T, E>
, mappingSome(v)
toOk(v)
andNone
toErr(err)
. -
okOrElse<
E> (E err()) → Result< T, E> -
Transforms the
Option<T>
into aResult<T, E>
, mappingSome(v)
toOk(v)
andNone
toErr(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
ornone
depending on the option. -
xor(
Option< T> optb) → Option<T> -
Returns
Some
if exactly one ofthis
,optb
isSome
, otherwise returnsNone
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited