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 returns other; else if this is Err, it repackages the contained error from Err<T,E> to Err<U, E>.
inherited
andThen<U>(Result<U, E> fn(T okV)) Result<U, E>
If this is Ok, it returns fn(v), where v is the contained value; else if this is Err, it repackages the contained error from Err<T,E> to Err<U, E>.
inherited
err() Option<E>
Converts this into an Option<E>, discarding the held T 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 function fn with the contained value.
inherited
inspectErr(void fn(E errE)) Result<T, E>
If this is Err, it calls the provided function fn with the contained error.
inherited
isErr() bool
Returns true if this is Err.
inherited
isErrAnd(bool predicate(E errE)) bool
Returns true if this is Err and the value inside of it matches predicate.
inherited
isOk() bool
Returns true if this is Ok.
inherited
isOkAnd(bool predicate(T okV)) bool
Returns true if this is Ok and the value inside of it matches a predicate.
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 with Ok<U,E>; else if this is Err, it repackages the contained error from Err<T, E> to Err<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 with Err<T, F>; else if this is Ok, it repackages the contained value (from Ok<T, E> to Ok<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 if this is Err, it returns orValue.
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 if this is Err, it returns the computed value of orElse.
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 and Option pattern matching snippets (VSCode) can be leveraged to make working with built-in pattern matching (switch and case) a breeze.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ok() Option<T>
Converts this into an Option<T>, discarding the held E value if this is Err.
inherited
or<F>(Result<T, F> other) Result<T, F>
If this is Ok, it repackages the contained value from Ok<T,E> to Ok<T, F>; else if this is Err, it returns other.
inherited
orElse<F>(Result<T, F> fn(E errE)) Result<T, F>
If this is Ok, it repackages the contained value from Ok<T,E> to Ok<T, F>; else if this is Err, it returns fn(e), where e 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 if this 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