Option<T> class sealed

Represents an optional value of type T.

An Option is either:

  • Some, which contains a value of type T
  • None, which does not contain a value

Adapted from Rust's Option, see more here: https://doc.rust-lang.org/std/option/index.html

Implementers
Available extensions
Annotations
  • @immutable

Constructors

Option.none()
Shortcut for None.new.
const
factory
Option.some(T value)
Shortcut for Some.new.
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

asNullable() → T?

Available on Option<T>, provided by the OptionConvenience extension

Returns Some.value or null for None.
map<R>(R mapper(T)) Option<R>

Available on Option<T>, provided by the OptionConvenience extension

Maps an 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 defaultValue) → T

Available on Option<T>, provided by the OptionConvenience extension

Returns Some.value if this is a Some. Otherwise, returns defaultValue (when None).
unwrapOrElse(T defaultFn()) → T

Available on Option<T>, provided by the OptionConvenience extension

Returns Some.value if this is a Some. Otherwise, calls and returns the result of defaultFn (when None).

Operators

operator ==(Object other) bool
The equality operator.
inherited