Option<T> class
class Option<T> { final T _value; final bool isDefined; Option._internal(this.isDefined, this._value); factory Option.none() => new Option._internal(false, null); factory Option.some(T value) => new Option._internal(true, value); T get value { if (isDefined) return _value; throw "undefined"; } // forall U, Option<U> map(U f(T)) Option map(f(T)) => isDefined ? new Option.some(f(this.value)) : this; bool operator ==(Option<T> other) => (isDefined && other.isDefined && _value == other._value) || (!isDefined && !other.isDefined); String toString() => isDefined ? "Option.some($_value)" : "Option.none()"; }
Constructors
factory Option.none() #
factory Option.none() => new Option._internal(false, null);
Properties
final bool isDefined #
final bool isDefined;
Operators
bool operator ==(Option<T> other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode
method as well to maintain consistency.
docs inherited from Object
bool operator ==(Option<T> other) => (isDefined && other.isDefined && _value == other._value) || (!isDefined && !other.isDefined);