Option<T> class
sealed
Optional value wrapper for Rust-style present-or-absent values.
Use None() when no value is present, and Some(value) when a value is
present even if that value is null.
const nickname = Some<String?>(null);
final label = switch (nickname) {
None<String?>() => 'missing',
Some<String?>(:final value) => value ?? 'present null',
};
Properties
Methods
-
andThen<
R> (Option< R> next(T value)) → Option<R> - Chains another option-producing operation when a value is present.
-
map<
R> (R mapper(T value)) → Option< R> - Maps a present value and leaves absent values unchanged.
-
match<
R> ({required R some(T value), required R none()}) → R - Pattern matches this option.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unwrapOr(
T fallback) → T -
Returns the present value, or
fallbackwhen this option is absent. -
unwrapOrElse(
T fallback()) → T - Returns the present value, or computes one when this option is absent.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited