Err<T, E> class
final
A type that represents an unsuccessful Result.
Pattern matching is recommended for interacting with Result types, for example:
final Result<int, String> foo = Err('Some err');
if (foo case Err(e: final err)) {
print('Error value: $err');
}
- Inheritance
- Available extensions
Constructors
- Err(E e)
-
const
Properties
- e → E
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
and<
U> (Result< U, E> other) → Result<U, E> -
If
this
is Ok, it returnsother
; else ifthis
is Err, it repackages the contained error fromErr<T,E>
toErr<U, E>
.inherited -
andThen<
U> (Result< U, E> fn(T okV)) → Result<U, E> -
If
this
is Ok, it returnsfn(v)
, wherev
is the contained value; else ifthis
is Err, it repackages the contained error fromErr<T,E>
toErr<U, E>
.inherited -
err(
) → Option< E> -
Converts
this
into anOption<E>
, discarding the heldT
value if this is Ok.inherited -
expect(
String message) → T -
Returns the contained Ok value.
inherited
-
expectErr(
String message) → E -
Returns the contained Err value.
inherited
-
inspect(
void fn(T okV)) → Result< T, E> -
If
this
is Ok, it calls the provided functionfn
with the contained value.inherited -
inspectErr(
void fn(E errE)) → Result< T, E> -
If
this
is Err, it calls the provided functionfn
with the contained error.inherited -
isErr(
) → bool -
Returns
true
ifthis
is Err.inherited -
isErrAnd(
bool predicate(E errE)) → bool -
Returns
true
ifthis
is Err and the value inside of it matchespredicate
.inherited -
isOk(
) → bool -
Returns
true
ifthis
is Ok.inherited -
isOkAnd(
bool predicate(T okV)) → bool -
Returns
true
ifthis
is Ok and the value inside of it matches apredicate
.inherited -
iter(
) → Iterable< T> -
Returns an Iterable of the possibly contained value.
inherited
-
map<
U> (U mapFn(T okV)) → Result< U, E> -
If
this
is Ok, it applies the provided function to the contained value and packages the newly computed value withOk<U,E>
; else ifthis
is Err, it repackages the contained error fromErr<T, E>
toErr<U, E>
.inherited -
mapErr<
F> (F mapFn(E errE)) → Result< T, F> -
If
this
is Err, it applies the provided function to the contained error and packages the newly computed error withErr<T, F>
; else ifthis
is Ok, it repackages the contained value (fromOk<T, E>
toOk<T, F>
).inherited -
mapOr<
U> (U orValue, U mapFn(T okV)) → U -
If
this
is Ok, it applies the provided function to the contained value and returns the newly computed value; else ifthis
is Err, it returnsorValue
.inherited -
mapOrElse<
U> (U orElse(), U mapFn(T okV)) → U -
If
this
is Ok, it applies the provided function to the contained value and returns the newly computed value; else ifthis
is Err, it returns the computed value oforElse
.inherited -
match<
U> ({required U err(E e), required U ok(T v)}) → U -
Alternative to doing pattern matching with
switch
expressions. Makes pattern matching simpler to invoke, given match being a class member; however,Result
andOption
pattern matching snippets (VSCode) can be leveraged to make working with built-in pattern matching (switch
andcase
) a breeze.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok(
) → Option< T> -
Converts
this
into anOption<T>
, discarding the heldE
value if this is Err.inherited -
or<
F> (Result< T, F> other) → Result<T, F> -
If
this
is Ok, it repackages the contained value fromOk<T,E>
toOk<T, F>
; else ifthis
is Err, it returnsother
.inherited -
orElse<
F> (Result< T, F> fn(E errE)) → Result<T, F> -
If
this
is Ok, it repackages the contained value fromOk<T,E>
toOk<T, F>
; else ifthis
is Err, it returnsfn(e)
, wheree
is the contained error.inherited -
sameContent(
Result< Object, Object> other) → bool -
Compares equality between two Results' contained values.
inherited
-
toJson(
Map< String, dynamic> okToJson(T okV), Map<String, dynamic> errToJson(E errE)) → Map<String, dynamic> -
Serializes this Result to a map.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
try_(
ErrPropagationToken< E> et) → T -
If
this
is Ok, it unwraps the value; else ifthis
is Err, it propagates the Err.e error by throwing an ErrPropagation.inherited -
unwrap(
) → T -
Returns the contained Ok value.
inherited
-
unwrapErr(
) → E -
Returns the contained Err value.
inherited
-
unwrapOr(
T orValue) → T -
Returns the contained Ok value or a provided value.
inherited
-
unwrapOrElse(
T orElse(E errE)) → T -
Returns the contained Ok value or computes it from the
orElse
closure.inherited
Operators
-
operator ==(
Object other) → bool -
Compares equality between two Result values. The generic types must
match. If only the contained value has to be checked, use
sameContent instead.
inherited