Result<T, E> class
abstract
Result is a type that represents either success (Ok
) or failure (Err
).
Result<T, E>
is the type used for returning and propagating errors. It is
an object with an Ok
value, representing success and containing a value,
and Err
, representing error and containing an error value.
Constructors
- Result()
- Result.err(E err)
-
Create an
Err
result with the given error.factory - Result.of(T catching())
-
Call the
catching
function and produce aResult
.factory - Result.ok(T s)
-
Create an
Ok
result with the given value.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
props
→ List<
Object?> -
The list of properties that will be used to determine whether
two instances are equal.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stringify → bool?
-
If set to
true
, the toString method will be overridden to output this instance's props.no setterinherited
Methods
-
and(
Result< T, E> res) → Result<T, E> -
Returns
res
if the result isOk
, otherwise returnsthis
. -
andThen(
Result< T, E> op(T)) → Result<T, E> -
Calls
op
with theOk
value if the result isOk
, otherwise returnsthis
. -
err(
) → Option< E> -
Converts the
Result
into anOption
containing the error, if any. Otherwise returnsNone
if the result is a value. -
expect(
String msg) → T -
Unwraps a result, yielding the content of an
Ok
. -
expectErr(
String msg) → E -
Unwraps a result, yielding the content of an
Err
. -
fold<
U, F> (U ok(T), F err(E)) → Result< U, F> -
Invoke either the
ok
or theerr
function based on the result. -
isErr(
) → bool -
Returns
true
if the option is aErr
value. -
isOk(
) → bool -
Returns
true
if the option is aOk
value. -
map<
U> (U op(T)) → Result< U, E> -
Maps a
Result<T, E>
toResult<U, E>
by applying a function to a containedOk
value, leaving anErr
value untouched. -
mapErr<
F> (F op(E)) → Result< T, F> -
Maps a
Result<T, E>
toResult<T, F>
by applying a function to a containedErr
value, leaving anOk
value untouched. -
mapOr<
U> (U op(T), U opt) → U - Applies a function to the contained value (if any), or returns the provided default (if not).
-
mapOrElse<
U> (U op(T), U errOp(E)) → U -
Maps a
Result<T, E>
toU
by applying a function to a containedOk
value, or a fallback function to a containedErr
value. -
match<
R> (R okop(T), R errop(E)) → R -
Invokes either the
okop
or theerrop
depending on the result. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok(
) → Option< T> -
Converts the
Result
into anOption
containing the value, if any. Otherwise returnsNone
if the result is an error. -
or(
Result< T, E> res) → Result<T, E> -
Returns
res
if the result is anErr
, otherwise returnsthis
. -
orElse(
Result< T, E> op(E)) → Result<T, E> -
Calls
op
with theErr
value if the result isErr
, otherwise returnsthis
. -
toString(
) → String -
A string representation of this object.
inherited
-
unwrap(
) → T -
Unwraps a result, yielding the content of an
Ok
. -
unwrapErr(
) → E -
Unwraps a result, yielding the content of an
Err
. -
unwrapOr(
T opt) → T -
Unwraps a result, yielding the content of an
Ok
. Else, it returnsopt
. -
unwrapOrElse(
T op(E)) → T -
Unwraps a result, yielding the content of an
Ok
. If the value is anErr
then it callsop
with its value. -
when<
R> ({required R ok(T), required R err(E)}) → R -
Invokes either
ok
orerr
depending on the result.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited