Result<T, E extends Object> class
sealed
A lightweight Result type inspired by Kotlin and Swift.
Use Result.success(value) for success and Result.failure(error) for
failure, then compose with APIs like map, flatMap, recover, and
fold.
Constructors
- Result.failure(E error)
-
Creates a failed Result containing
error.constfactory - Result.success(T value)
-
Creates a successful Result containing
value.constfactory
Properties
- errorOrNull → E?
-
Returns the failure error, or
nullwhen this is a success.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isFailure → bool
-
Whether this instance is a Failure.
no setter
- isSuccess → bool
-
Whether this instance is a Success.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- valueOrNull → T?
-
Returns the success value, or
nullwhen this is a failure.no setter
Methods
-
flatMap<
R> (Result< R, E> transform(T value)) → Result<R, E> - Chains another Result-producing transform on success.
-
flatMapError<
F extends Object> (Result< T, F> transform(E error)) → Result<T, F> - Chains another Result-producing transform on failure.
-
fold<
R> (R onSuccess(T value), R onFailure(E error)) → R - Maps this result to a single value by handling both cases.
-
getOrElse(
T onFailure(E error)) → T - Returns the success value, or computes a fallback from the error.
-
getOrThrow(
) → T - Returns the success value, or throws the contained failure error.
-
map<
R> (R transform(T value)) → Result< R, E> - Transforms the success value while preserving the error type.
-
mapError<
F extends Object> (F transform(E error)) → Result< T, F> - Transforms the failure error while preserving the success type.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recover(
T transform(E error)) → Result< T, E> -
Converts a failure into success using
transform. -
toString(
) → String -
A string representation of this object.
inherited
-
when<
R> ({required R success(T value), required R failure(E error)}) → R - Named-parameter variant of fold for improved readability.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited