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.

Implementers
Annotations

Constructors

Option.none()
Creates a None instance.
const
factory
Option.some(TValue value)
Creates a Some instance.
const
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

map<T>({required T onSome(TValue value), required T onNone()}) → T
Maps the Option to a new Option based on the provided onSome and onNone 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

Static Methods

from<TValue>(TValue? value) Option<TValue>