Ok<T extends Object, E extends Object> class
An Ok<T, E>
is a Result
that represents the successful value.
You can create an Ok
using either the Ok()
constructor or the
Result.ok()
factory constructor.
- Inheritance
- Available extensions
Constructors
- Ok(T s)
-
Create an
Ok
result with the given value.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
props
→ List<
Object?> -
The list of properties that will be used to determine whether
two instances are equal.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stringify → bool
-
If set to
true
, the toString method will be overridden to output this instance's props.no setter
Methods
-
and<
U extends Object> (Result< U, E> res) → Result<U, E> -
Returns
res
if the result isOk
, otherwise returnsthis
.override -
andThen<
U extends Object> (Result< U, E> op(T)) → Result<U, E> -
Calls
op
with theOk
value if the result isOk
, otherwise returnsthis
.override -
andThenAsync<
U extends Object> (Future< Result< op(T)) → Future<U, E> >Result< U, E> > -
Asynchronously calls
op
with theOk
value if the result isOk
, otherwise returnsthis
.override -
err(
) → Option< E> -
Converts the
Result
into anOption
containing the error, if any. Otherwise returnsNone
if the result is a value.override -
expect(
String msg) → T -
Unwraps a result, yielding the content of an
Ok
.override -
expectErr(
String msg) → E -
Unwraps a result, yielding the content of an
Err
.override -
fold<
U extends Object, F extends Object> (U ok(T), F err(E)) → Result< U, F> -
Invoke either the
ok
or theerr
function based on the result.override -
foldAsync<
U extends Object, F extends Object> (Future< U> ok(T), Future<F> err(E)) → Future<Result< U, F> > -
Asynchronously invoke either the
ok
or theerr
function based on the result.override -
isErr(
) → bool -
Returns
true
if the option is aErr
value.override -
isOk(
) → bool -
Returns
true
if the option is aOk
value.override -
map<
U extends Object> (U op(T)) → Result< U, E> -
Maps a
Result<T, E>
toResult<U, E>
by applying a function to a containedOk
value, leaving anErr
value untouched.override -
mapAsync<
U extends Object> (Future< U> op(T)) → Future<Result< U, E> > -
Maps a
Result<T, E>
toResult<U, E>
by applying an asynchronous function to a containedOk
value, leaving anErr
value untouched.override -
mapErr<
F extends Object> (F op(E)) → Result< T, F> -
Maps a
Result<T, E>
toResult<T, F>
by applying a function to a containedErr
value, leaving anOk
value untouched.override -
mapErrAsync<
F extends Object> (Future< F> op(E)) → Future<Result< T, F> > -
Maps a
Result<T, E>
toResult<T, F>
by applying a function to a containedErr
value, leaving anOk
value untouched.override -
mapOr<
U> (U op(T), U opt) → U -
Applies a function to the contained value (if any), or returns the
provided default (if not).
override
-
mapOrAsync<
U> (Future< U> op(T), U opt) → Future<U> -
Applies an asynchronous function to the contained value (if any),
or returns the provided default (if not).
override
-
mapOrElse<
U> (U op(T), U errOp(E)) → U -
Maps a
Result<T, E>
toU
by applying a function to a containedOk
value, or a fallback function to a containedErr
value.override -
mapOrElseAsync<
U> (Future< U> op(T), Future<U> errOp(E)) → Future<U> -
Maps a
Result<T, E>
toU
by applying a function to a containedOk
value, or a fallback function to a containedErr
value.override -
match<
R> (R okop(T), R errop(E)) → R -
Invokes either the
okop
or theerrop
depending on the result.override -
matchAsync<
R> (Future< R> okop(T), Future<R> errop(E)) → Future<R> -
Asynchronously invokes either the
okop
or theerrop
depending on the result.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok(
) → Option< T> -
Converts the
Result
into anOption
containing the value, if any. Otherwise returnsNone
if the result is an error.override -
or<
F extends Object> (Result< T, F> res) → Result<T, F> -
Returns
res
if the result is anErr
, otherwise returnsthis
.override -
orElse<
F extends Object> (Result< T, F> op(E)) → Result<T, F> -
Calls
op
with theErr
value if the result isErr
, otherwise returnsthis
.override -
orElseAsync<
F extends Object> (Future< Result< op(E)) → Future<T, F> >Result< T, F> > -
Calls
op
with theErr
value if the result isErr
, otherwise returnsthis
.override -
toString(
) → String -
A string representation of this object.
inherited
-
unwrap(
) → T -
Unwraps a result, yielding the content of an
Ok
.override -
unwrapErr(
) → E -
Unwraps a result, yielding the content of an
Err
.override -
unwrapOr(
T opt) → T -
Unwraps a result, yielding the content of an
Ok
. Else, it returnsopt
.override -
unwrapOrElse(
T op(E)) → T -
Unwraps a result, yielding the content of an
Ok
. If the value is anErr
then it callsop
with its value.override -
unwrapOrElseAsync(
Future< T> op(E)) → Future<T> -
Unwraps a result, yielding the content of an
Ok
. If the value is anErr
then it asynchronously callsop
with its value.override -
when<
R> ({required R ok(T), required R err(E)}) → R -
Invokes either
ok
orerr
depending on the result.override -
whenAsync<
R> ({required Future< R> ok(T), required Future<R> err(E)}) → Future<R> -
Asynchronously invokes either
ok
orerr
depending on the result.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited