Option<TValue> class
sealed
A type that can be either Some or None.
Some is a type that contains a value of type TValue
.
None is a type that does not contain a value.
This class is meant to be used as a return type for functions that may return either a value or nothing, to avoid the need for null checks.
Constructors
- Option.none()
-
Creates a None instance.
constfactory
- Option.some(TValue value)
-
Creates a Some instance.
constfactory
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
-
map<
T> ({required T onSome(TValue value), required T onNone()}) → T -
Maps the Option to a new Option based on the provided
onSome
andonNone
functions. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onNone(
void onNone()) → Option< TValue> -
Calls the provided
onNone
function if the Option is a None instance. -
onSome(
void onSome(TValue value)) → Option< TValue> -
Calls the provided
onSome
function if the Option is a Some instance. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited