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.

Implementers

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 if result is Ok. Throws contained result.err if result is Err.
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 is Err then returns this Err as is. If result is Ok 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 is Err then returns this Err as is. If result is Ok 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 is Err then returns this Err as is. If result is Ok 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() is Result - returns it as is. If call of f() throws exception, then returns Err.
pipeAsync<T2>(Future f(T)) Future<Result<T2>>
If result is Err then returns this Err as is. If result is Ok then returns result of call await f(result.val). If result of call f() is null - returns Err('function returned null'). If result of call f() is Result - returns it as is. If call of f() throws exception, then returns Err.
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 a Err, then replaces internal err with newErr value. And returns changed result; If the Result is a Ok, then return unchanged Result 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 if result is Ok. Returns default_value if result is Err.
unwrapOrElse(T elseFunc(Error? e)) → T
Returns result.val if result is Ok. Returns call of elseFunc(result.err) if result is Err.

Operators

operator ==(Object other) bool
The equality operator.
inherited