Result<Value> class
sealed
The outcome of a service operation — either a Success carrying a typed value, or a Failure carrying optional context.
Results are never thrown; they are returned and composed. Use andThen to chain steps, onSuccessOf/onFailureOf to react to specific outcomes, and when when exhaustive handling is required.
See ServiceBase for the idiomatic way to produce results inside a service.
Properties
- context → Object?
-
The failure context, or
nullif this is a Success.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isFailure → bool
-
Whether this result is a Failure.
no setter
- isSuccess → bool
-
Whether this result is a Success.
no setter
- outcome → String
-
The primary outcome tag. Shortcut for
outcomes.first.no setter -
outcomes
→ List<
String> -
All outcome tags carried by this result.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → Value?
-
The success value, or
nullif this is a Failure.no setter
Methods
-
andThen<
NextValue> (Result< NextValue> nextStep(Value value)) → Result<NextValue> - Chains the next step when this result is a success; short-circuits on failure.
-
map<
MappedValue> (MappedValue transform(Value value)) → Result< MappedValue> - Transforms the success value without changing the outcome tags.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onFailure(
void callback(String outcome, Object? context)) → Result< Value> -
Runs
callbackif this is a failure, passing the primary outcome and context. -
onFailureOf(
Object? matchOutcomes, void callback(Object? context)) → Result< Value> -
Runs
callbackif this is a failure and its outcomes intersect withmatchOutcomes. -
onSuccess(
void callback(Value value)) → Result< Value> -
Runs
callbackif this is a success; does nothing on failure. -
onSuccessOf(
Object? matchOutcomes, void callback(Value value)) → Result< Value> -
Runs
callbackif this is a success and its outcomes intersect withmatchOutcomes. -
orElse(
Result< Value> recovery(List<String> outcomes, Object? context)) → Result<Value> - Recovers from a failure by producing a new result; ignored if already successful.
-
toString(
) → String -
A string representation of this object.
inherited
-
when<
Output> ({required Output success(List< String> outcomes, Value value), required Output failure(List<String> outcomes, Object? context)}) → Output - Forces exhaustive handling of both the success and failure cases.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited