Ok<T> class
Represent success result. See isOk, val getters and unpack, for getting it's value. Ok has Result as superclass. Ok(123) is Result == true
Constructors
- Ok(T? _val)
Properties
- err → Error?
-
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isErr → bool
-
no setterinherited
- isOk → bool
-
no setterinherited
- 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 setterinherited - val → T?
-
no setterinherited
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.inherited -
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.inherited -
onErr(
dynamic f(Error)) → Result< T> -
Calls f(result.err) with side effect if this result is Err.
Anyway returns this result as is.
inherited
-
onOk(
dynamic f(T)) → Result< T> -
Calls f(result.val) with side effect if this result is Ok.
Anyway returns this result as is.
inherited
-
onResult(
dynamic f(Result< T> )) → Result<T> -
Calls f(this) with side effect and return this as is.
inherited
-
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.inherited -
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.inherited -
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
.inherited -
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
.inherited -
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;
inherited
-
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;inherited -
test(
bool testFunction(Result< T> ), String failedTestMsg) → Result<T> -
Test this result and return Ok or Err.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unwrapOrDefault(
T default_value) → T -
Returns
val
ifresult
isOk
. Returnsdefault_value
ifresult
isErr
.inherited -
unwrapOrElse(
T elseFunc(Error? e)) → T -
Returns
result.val
ifresult
isOk
. Returns call ofelseFunc(result.err)
ifresult
isErr
.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited