Result<T, E extends Object> class sealed

A wrapper type that may either be an error or a value.

The Result type represents a value that is either Ok to use or is an Err and should be handled. This should be preferred over try catch as it forces developers handle all possible states of the result through pattern matching.

Implementers

Constructors

Result.err(E error)
Instantiate an Error type.
factory
Result.ok(T value)
Instantiate an Ok type.
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

call() → dynamic
A direct handle to the value or error.
ifErr(ResultCallback<E> callback) → void
Run the callback if the Result is Err.
ifOk(ResultCallback<T> callback) → void
Run the callback if the Result is Ok.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
unwrap() → T
Unwrap the Result and either return the value if Ok or panic if it is Err.
unwrapUnlessErr({required T then}) → T
Unwrap the Result and return the value if Ok, otherwise then return a default value.
unwrapWithErr({required ErrorHandler<T, E> handledBy}) → T
Unwrap the Result and return the value if Ok, otherwise let the Err be handledBy a callback function that computes the default value of the failed Result.

Operators

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

Static Properties

isErr bool
True if the Result is Err; false otherwise.
getter/setter pair
isOk bool
True if the Result is Ok; false otherwise.
getter/setter pair