Ok<T, E> class
A type that represents the successful Result of something.
Pattern matching is recommended for interacting with Result types.
Result<int, String> foo = Ok(42);
if (foo case Ok(value: var bar)) {
print('Ok value: $bar');
}
- Inheritance
- Available extensions
Constructors
- Ok(T value)
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
final
Methods
-
and<
U> (Result< U, E> other) → Result<U, E> -
Returns a
Result
value as Err<U, E> if thisResult
is Err<T, E>, otherwise returnsother
.inherited -
andThen<
U> (Result< U, E> fn(T)) → Result<U, E> -
Returns a
Result
value as Err<U, E> if thisResult
is Err<T, E>, otherwise callsfn
with the held Ok value and returns the returnedResult
.inherited -
call(
) → T -
Shortcut to call Result.unwrap().
inherited
-
err(
) → Option< E> -
Converts this
Result<T, E>
into an Option<E>, discarding the held value if this is Ok.inherited -
expect(
String message) → T -
Returns the held value of this
Result
if it is Ok. Throws a ResultError with the givenmessage
and held Err value if thisResult
is Err.inherited -
expectErr(
String message) → E -
Returns the held value of this
Result
if it is Err. Throws a ResultError with the givenmessage
and held Ok value if thisResult
is Ok.inherited -
inspect(
void fn(T)) → Result< T, E> -
Calls the provided function with the contained value if this
Result
is Ok.inherited -
inspectErr(
void fn(E)) → Result< T, E> -
Calls the provided function with the contained error value if this
Result
is Err.inherited -
isErr(
) → bool -
Returns whether or not this
Result
is Err.inherited -
isErrAnd(
bool predicate(E)) → bool -
Returns whether or not this
Result
is Err and that the held error value matches the given predicate.inherited -
isOk(
) → bool -
Returns whether or not this
Result
is Ok.inherited -
isOkAnd(
bool predicate(T)) → bool -
Returns whether or not this
Result
is Ok and that the held value matches the given predicate.inherited -
iter(
) → Iterable< T> -
Returns an Iterable of the held value.
inherited
-
map<
U> (U mapFn(T)) → Result< U, E> -
Maps a
Result<T, E>
to aResult<U, E>
using the given function with the held value.inherited -
mapErr<
F> (F mapFn(E)) → Result< T, F> -
Maps a
Result<T, E>
to aResult<T, F>
using the given function with the held value.inherited -
mapOr<
U> (U orValue, U mapFn(T)) → Result< U, E> -
Maps a
Result<T, E>
to aResult<U, E>
using the given function with the held value if theResult<T, E>
is Ok. Otherwise returns the providedorValue
asOk(orValue)
.inherited -
mapOrElse<
U> (U orFn(), U mapFn(T)) → Result< U, E> -
Maps a
Result<T, E>
to aResult<U, E>
using the givenmapFn
function with the held value if theResult
is Ok. Otherwise returns the result oforFn
asOk(orFn())
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok(
) → Option< T> -
Converts this
Result<T, E>
into an Option<T>, discarding the held error value if this is Err.inherited -
or<
F> (Result< T, F> other) → Result<T, F> -
Returns a
Result
value as Ok<T, F> if thisResult
is Ok<T, E>, otherwise returnsother
.inherited -
orElse<
F> (Result< T, F> fn(E)) → Result<T, F> -
Returns a
Result
value as Ok<T, F> if thisResult
is Ok<T, E>, otherwise callsfn
with the held Err value and returns the returnedResult
.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
unwrap(
) → T -
Returns the held value of this
Result
if it is Ok.inherited -
unwrapErr(
) → E -
Returns the held value of this
Result
if it is Err.inherited -
unwrapOr(
T orValue) → T -
Returns the held value of this
Result
if it is Ok, or the given value if thisResult
is Err.inherited -
unwrapOrElse(
T elseFn()) → T -
Returns the held value of this
Result
if it is Ok, or returns the returned value fromelseFn
if thisResult
is Err.inherited
Operators
-
operator ==(
Object other) → bool -
Compare equality between two
Result
values.inherited