Result<T, E extends Object> class sealed

A sealed class representing the result of an operation that can succeed or fail

Annotations
  • @immutable

Constructors

Result.failure(E error)
Creates a failed result with the given error
const
factory
Result.success(T value)
Creates a successful result with the given value
const
factory

Properties

failureOrNull → E?
Returns the error if this is a failure, or null if this is a success
no setter
hashCode int
The hash code for this object.
no setterinherited
isFailure bool
Returns true if this result represents a failure
no setter
isSuccess bool
Returns true if this result represents a success
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
successOrNull → T?
Returns the success value if this is a success, or null if this is a failure
no setter

Methods

errorOrNull() → E?
Returns the error if this is a failure, or null if this is a success
flatMap<U>(Result<U, E> mapper(T)) Result<U, E>
Flat maps the success value using the given function, preserving failures
fold<U>(U onSuccess(T), U onFailure(E)) → U
Folds this result into a single value using the appropriate function
get() → T
Returns the success value if this is a success, or throws the error if this is a failure
getOrElse(T defaultValue) → T
Returns the success value if this is a success, or the given default value if this is a failure
getOrNull() → T?
Returns the success value if this is a success, or null if this is a failure
map<U>(U mapper(T)) Result<U, E>
Maps the success value using the given function, preserving failures
mapError<F extends Object>(F mapper(E)) Result<T, F>
Maps the error using the given function, preserving successes
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onFailure(void action(E)) Result<T, E>
Executes the given function with the error if this is a failure
onSuccess(void action(T)) Result<T, E>
Executes the given function with the success value if this is a success
toString() String
A string representation of this object.
inherited

Operators

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