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.valifresultisOk. Throws containedresult.errifresultisErr.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
resultisErrthen returns thisErras is. IfresultisOkthen 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
resultisErrthen returns thisErras is. IfresultisOkthen 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
resultisErrthen returns thisErras is. IfresultisOkthen 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
resultisErrthen returns thisErras is. IfresultisOkthen 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
Resultis aErr, then replaces internalerrwithnewErrvalue. And returns changed result; If theResultis aOk, then return unchangedResultas 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
valifresultisOk. Returnsdefault_valueifresultisErr. -
unwrapOrElse(
T elseFunc(Error? e)) → T -
Returns
result.valifresultisOk. Returns call ofelseFunc(result.err)ifresultisErr.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited