Result<T> class sealed

A sealed class to represent the result of an operation.

It can be either a Result.success with a value of type T or a Result.error with a BaseError.

Constructors

Result.error(BaseError error)
A failed result with a BaseError.
factory
Result.success(T value)
A successful result with a value of type T.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isError bool
Returns true if this is a Result.error.
no setter
isSuccess bool
Returns true if this is a Result.success.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

asyncFlatMap<R>(FutureResult<R> func(T value)) FutureResult<R>
async flat map result
errorOrNull() BaseError?
Returns the error if this is a Result.error or null otherwise.
flatMap<R>(Result<R> func(T value)) Result<R>
flat map result
fold<R>(R onError(BaseError failure), R onSuccess(T value)) → R
Returns the result of applying one of the functions to this result.
getOrNull() → T?
Returns the value if this is a Result.success or null otherwise.
map<R>(R func(T value)) Result<R>
map result
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

Static Methods

from<R, T>(T func(), {R onSuccess(T result)?, BaseError onError(Object error, StackTrace stackTrace)?}) Result<R>
Constructs a Result from a function. If the function completes successfully, the Result is a success with the value of the function. If the function fails, the Result is an error with the error of the function.
fromAsync<R, T>(Future<T> func(), {R onSuccess(T result)?, BaseError onError(Object exception, StackTrace stackTrace)?}) FutureResult<R>
Constructs a Result from a Future. If the Future completes successfully, the Result is a success with the value of the Future. If the Future fails, the Result is an error with the error of the Future.
fromPredicate<R>(bool predicate(), R onSuccess(), BaseError onError()) Result<R>
Constructs a Result by testing a condition. If the condition is true, the Result is a success with a certain value. If the condition is false, the Result is an error with a certain error.