TaskResult<T extends Object, E extends Object> class abstract

A type that represents either ok/success or err/failure result, and is referred from rust's std::Result enum.

Note that if you want to catch exceptions from async task such as Future.microtask, you can not only use runZonedGuarded, but also use Future<Result> as return type and await the Future whenever you want.

Implementers

Constructors

TaskResult.err(E _error)
Creates an err result, with given non-null data. Note that this constructor can not be used to instantiate TaskResult, use Err instead.
const
TaskResult.ok(T _data)
Creates an ok result, with given non-null data. Note that this constructor can not be used to instantiate TaskResult, use Ok instead.
const

Properties

data → T?
Returns the data of the result, this value will not be null if isOk is true.
no setter
error → E?
Returns the error of the result, this value will not be null if isErr is true.
no setter
hashCode int
The hash code for this object.
no setteroverride
isErr bool
Returns true if the result is err, which means error is not null.
no setter
isOk bool
Returns true if the result is ok, which means data is not null.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

and<U extends Object>(TaskResult<U, E> res) TaskResult<U, E>
Returns res if ok, otherwise returns error in corresponding type.
andThen<U extends Object>(TaskResult<U, E> op(T data)) TaskResult<U, E>
Returns the result computed by op, otherwise returns error in corresponding type.
andThenAsync<U extends Object>(FutureOr<TaskResult<U, E>> op(T data)) Future<TaskResult<U, E>>
This is the async version of andThen.
expect(Object msg) → T
Unwraps the result, returns data if ok, otherwise throws given msg.
expectErr(Object msg) → E
Unwraps the result, returns error if err, otherwise throws given msg.
inspect(void op(T data)) TaskResult<T, E>
Calls given op if ok and returns the result as is.
inspectAsync(FutureOr<void> op(T data)) Future<TaskResult<T, E>>
This is the async version of inspect.
inspectErr(void op(E error)) TaskResult<T, E>
Calls given op if err and returns the result as is.
inspectErrAsync(FutureOr<void> op(E error)) Future<TaskResult<T, E>>
This is the async version of inspectErr.
map<U extends Object>(U op(T data)) TaskResult<U, E>
Maps the result to result with data computed by given op.
mapAsync<U extends Object>(FutureOr<U> op(T data)) Future<TaskResult<U, E>>
This is the async version of map.
mapErr<F extends Object>(F op(E error)) TaskResult<T, F>
Maps the result to result with target error computed by given op.
mapErrAsync<F extends Object>(FutureOr<F> op(E error)) Future<TaskResult<T, F>>
This is the async version of mapOrElse.
mapOr<U extends Object>(U defaultValue, U op(T data)) TaskResult<U, E>
Maps the result to result with data computed by given defaultValue value and op.
mapOrAsync<U extends Object>(U defaultValue, FutureOr<U> op(T data)) Future<TaskResult<U, E>>
This is the async version of mapOr.
mapOrElse<U extends Object>(U defaultValue(E error), U op(T data)) TaskResult<U, E>
Maps the result to result with data computed by given defaultValue and op.
mapOrElseAsync<U extends Object>(FutureOr<U> defaultValue(E error), FutureOr<U> op(T data)) Future<TaskResult<U, E>>
This is the async version of mapOrElse.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
or<F extends Object>(TaskResult<T, F> res) TaskResult<T, F>
Returns res if err, otherwise returns data in corresponding type.
orElse<F extends Object>(TaskResult<T, F> op(E error)) TaskResult<T, F>
Returns the result computed by op, otherwise returns data in corresponding type.
orElseAsync<F extends Object>(FutureOr<TaskResult<T, F>> op(E error)) Future<TaskResult<T, F>>
This is the async version of orElse.
toString() String
A string representation of this object.
override
unwrap() → T
Unwraps the result, returns data if ok, otherwise throws error.
unwrapErr() → E
Unwraps the result, returns error if err, otherwise throws data.
unwrapOr(T defaultValue) → T
Unwraps the result, returns data if ok, otherwise returns given defaultValue.
unwrapOrElse(T op(E error)) → T
Unwraps the result, returns data if ok, otherwise computes it from given op.
unwrapOrElseAsync(FutureOr<T> op(E error)) Future<T>
This is the async version of unwrapOrElse.

Operators

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