Option<MAYBE> class

Represents a nullable value. Ensures safe handling of nullable values by enforcing the explicit handling of both states of the value. Can have the state of something (some) or nothing (none).

Constructors

Option.none()
Returns a const Option where the inner value is always null.
factory
Option.of(MAYBE? maybeValue)
Creates an Option from a nullable maybeValue.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isNone bool
True if inner value is null.
no setter
isSome bool
True if inner value is not null.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get(MAYBE fallback) → MAYBE
Gets the inner value if not null or fallback otherwise.
getOr(MAYBE fallback()) → MAYBE
Gets the inner value if not null or result of fallback otherwise.
getOrAsync(Future<MAYBE> fallback()) Future<MAYBE>
Async version of Option.getOr.
getUnsafe() → MAYBE?
Returns the inner value as nullable. Only use this if necessary.
ifNone<RETURN>(RETURN onNone()) Option<RETURN>
Calls onNone if this.isNone and returns its value in a new Option.
ifNoneAsync<RETURN>(Future<RETURN> onNone()) Future<Option<RETURN>>
Async version of Option.ifNone.
ifSome<RETURN>(RETURN onSome(MAYBE some)) Option<RETURN>
Calls onSome if this.isSome and returns its value in a new Option.
ifSomeAsync<RETURN>(Future<RETURN> onSome(MAYBE some)) Future<Option<RETURN>>
Async version of Option.ifSome.
match<RETURN>({required RETURN onSome(MAYBE some), required RETURN onNone()}) → RETURN
Calls the matching function and returns its value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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