Result<T, E> class
Result<T, E> is a type that represents either success or failure
It can be used to transparently return results from functions than can possibly fail, whereas exceptions have to be documented manually.
Constructors
- Result.err(E error)
-
Creates a failed result from
error
const - Result.ok(T value)
-
Creates a successful result from
value
const
Properties
- errorOrNull → E?
-
Returns the error if
isOErr
is true, otherwise returns nullno setter - hashCode → int
-
The hash code for this object.
no setteroverride
- isErr → bool
-
Whether this is a failed result
no setter
- isOk → bool
-
Whether this is a succesful result
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- valueOrNull → T?
-
Returns the value if isOk is true, otherwise returns null
no setter
Methods
-
cast<
U, F> () → Result< U, F> - Returns a Result<U, F> where value/error is cast to the corresponding type.
-
contains(
T value) → bool -
Returns true is isOk is true and if
value
equals value, otherwise returns false -
containsErr(
E error) → bool -
Returns true if isErr is true and if
error
equals error, otherwise returns false -
errorOr(
E defaultError) → E -
Returns the error if
isOErr
is true, otherwise returnsdefaultError
-
flatMap<
U> (Result< U, E> f(T)) → Result<U, E> -
Maps Result<T, E> to Result<U, E>, leaving an
Err
value untouched. -
flatMapOrElse<
U, F> (Result< U, F> f(T), Result<U, F> e(E)) → Result<U, F> -
Maps Result<T, E> to Result<U, E>, leaving an
Err
value untouched. -
map<
U> (U f(T)) → Result< U, E> -
Maps the value of a successful Result<T, E> from
T
toU
, leaving an error untouched. -
mapErr<
F> (F f(E)) → Result< T, F> -
Maps Result<T, E> to Result<T, F>, leaving an
Ok
value untouched. -
mapOrElse<
U> (U ok(T), U err(E)) → U -
Maps a Result<T, E> to
U
by applyingok
to a contained value orerr
to a contained error. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
valueOr(
T defaultValue) → T -
Returns the value if isOk is true, otherwise returns
defaultValue
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override