Result<T> class
sealed
A value that is either Ok or Err.
Dart's C0 contract fixes the error channel to Problem, retaining the single generic parameter of the Flutter seed while matching the Bun capability names.
Constructors
- Result.err(Problem problem)
-
Creates an Err result.
constfactory
- Result.fromSerial(ResultSerial serial, {required T decodeOk(Object? value), Problem decodeErr(Object? value)?})
-
Decodes the C0
['ok', value] | ['err', problem]wire form.factory - Result.ok(T value)
-
Creates an Ok result.
constfactory
Properties
Methods
-
andThen<
R> (Result< R> mapper(T value)) → Result<R> - Chains another fallible operation after an Ok value.
-
err(
) → Option< Problem> -
Projects the Err channel into an
Option. -
exec(
void sideEffect(T value), {required Problem onException(Object error, StackTrace stackTrace)}) → Result< T> - Runs an Ok-side effect and explicitly maps a thrown object to Problem.
-
map<
R> (R mapper(T value)) → Result< R> - Transforms an Ok value and leaves an Err untouched.
-
mapErr(
Problem mapper(Problem problem)) → Result< T> - Transforms an Err problem and leaves an Ok untouched.
-
match<
R> ({required R ok(T value), required R err(Problem problem)}) → R - Folds both variants into one return type.
-
native(
) → Object? - Returns the payload of whichever variant is present.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok(
) → Option< T> -
Projects the Ok channel into an
Option. -
run(
void sideEffect(T value)) → Result< T> - Runs an Ok-side effect without capturing exceptions.
-
serial(
{Object? encodeOk(T value)?}) → ResultSerial - Encodes this result using the C0 tagged-array wire contract.
-
toString(
) → String -
A string representation of this object.
inherited
-
unwrap(
) → T -
Returns the Ok value or throws
UnwrapError. -
unwrapErr(
) → Problem -
Returns the Err problem or throws
UnwrapError. -
unwrapOr(
T fallback) → T -
Returns the Ok value, or
fallbackfor Err. -
unwrapOrElse(
T fallback(Problem problem)) → T - Returns the Ok value, or computes a fallback from the Err problem.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited