Result<T, E> class
sealed
A functional type representing either a Success or a Failure.
Use Result to handle errors without try-catch blocks.
Example:
Result<int, String> divide(int a, int b) {
if (b == 0) return Result.error('Cannot divide by zero');
return Result.ok(a ~/ b);
}
Constructors
- Result.error(E error)
-
Creates a failed result.
factory
- Result.ok(T value)
-
Creates a successful result.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isFailure → bool
-
Returns true if this constitutes a failure.
no setter
- isSuccess → bool
-
Returns true if this constitutes a success.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- unwrap → T
-
Returns the value if successful, otherwise throws the error.
no setter
Methods
-
map<
U> (U f(T value)) → Result< U, E> - Maps the value if successful, otherwise returns the error as is.
-
match<
R> (R onSuccess(T value), R onError(E error)) → R - Executed providing the value if successful, or the error if failed.
-
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