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',
};
Implementers

Properties

hashCode int
The hash code for this object.
no setterinherited
isNone bool
Whether this option is None.
no setter
isSome bool
Whether this option is Some.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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 fallback when 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