Result<T> class
abstract
Abstract class. Represent common type Result, which may be a Ok or Err. Don't instantiate it. Use implementations: Ok() and Err() instead.
Constructors
- Result()
Properties
- err → Error?
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isErr → bool
-
no setter
- isOk → bool
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- unwrap → T
-
Returns
result.val
ifresult
isOk
. Throws containedresult.err
ifresult
isErr
.no setter - val → T?
-
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok<
T2> (T2 f(T)) → Result< T2> -
If
result
isErr
then returns thisErr
as is. Ifresult
isOk
then returns result of call f(result.val). Result of call f() must be a value of type T2. -
okAsync<
T2> (Future< T2> f(T)) → Future<Result< T2> > -
The same as ok(), but wrapped with Future<...>.
If
result
isErr
then returns thisErr
as is. Ifresult
isOk
then returns result of call f(result.val). Result of call f() must be a value of type T2. -
onErr(
dynamic f(Error)) → Result< T> - Calls f(result.err) with side effect if this result is Err. Anyway returns this result as is.
-
onOk(
dynamic f(T)) → Result< T> - Calls f(result.val) with side effect if this result is Ok. Anyway returns this result as is.
-
onResult(
dynamic f(Result< T> )) → Result<T> - Calls f(this) with side effect and return this as is.
-
or(
T? f()) → Result< T> -
If this result is Ok, then returns it as is.
If this result is Err, then call
result = f()
. If result of call f() is null, then returns Err. If result of call f() is value , then return Ok(value). If call of f() throws exception, then returns Err. -
orAsync(
Future< T> f()) → Future<Result< T> > -
If this result is Ok, then returns it as is.
If this result is Err, then call
result = await f()
. If result of call f() is null, then returns Err. If result of call f() is value, then return Ok(value). If call of f() throws exception, then returns Err. -
pipe<
T2> (dynamic f(T)) → Result< T2> -
If
result
isErr
then returns thisErr
as is. Ifresult
isOk
then returns result of call f(result.val). If result of call f() is null - returns Err('function returned null'). If result of call f() isResult
- returns it as is. If call of f() throws exception, then returnsErr
. -
pipeAsync<
T2> (Future f(T)) → Future< Result< T2> > -
If
result
isErr
then returns thisErr
as is. Ifresult
isOk
then returns result of callawait f(result.val)
. If result of call f() is null - returns Err('function returned null'). If result of call f() isResult
- returns it as is. If call of f() throws exception, then returnsErr
. -
replacePossibleError(
Error oldErrorReplacer(Error oldErr)) → Result< T> - If the Result is a Err, then replaces internal err with result if given function oldErrorReplacer. Function oldErrorReplacer should take old error and return new error; And returns changed result; If the Result is a Ok, then return unchanged Result as is;
-
replacePossibleErrorWith(
Error newErr) → Result< T> -
If the
Result
is aErr
, then replaces internalerr
withnewErr
value. And returns changed result; If theResult
is aOk
, then return unchangedResult
as is; -
test(
bool testFunction(Result< T> ), String failedTestMsg) → Result<T> - Test this result and return Ok or Err.
-
toString(
) → String -
A string representation of this object.
override
-
unwrapOrDefault(
T default_value) → T -
Returns
val
ifresult
isOk
. Returnsdefault_value
ifresult
isErr
. -
unwrapOrElse(
T elseFunc(Error? e)) → T -
Returns
result.val
ifresult
isOk
. Returns call ofelseFunc(result.err)
ifresult
isErr
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited