Ok<S, F extends Object> class final

Ok Result.

Returned when the result is an expected value

Implemented types
Available extensions

Constructors

Ok(S ok)
Receives the S param as the ok result.
const

Properties

hashCode int
The hash code for this object.
no setteroverride
ok → S
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

and<S2>(Result<S2, F> other) Result<S2, F>
Performs an "and" operation on the results. Returns the first result that is Err, otherwise if both are Ok, other Ok Result is returned.
override
andThen<W>(Result<W, F> fn(S ok)) Result<W, F>
If Ok, Returns a new Result by passing the Ok value to the provided function.
override
andThenErr<W extends Object>(Result<S, W> fn(F error)) Ok<S, W>
/ If Err, Returns a new Result by passing the Err value to the provided function.
override
context(Object context) Result<S>

Available on Result<S>, provided by the AnyhowResultExtensions extension

If Result is Ok returns this. Otherwise, returns an Error with the additional context. The context should not be an instance of Error.
context(Object context) Ok<S>

Available on Ok<S>, provided by the AnyhowOkExtensions extension

returns this
copy() Ok<S, F>
Performs a shallow copy of this result.
override
expect(String message) → S
Returns the ok value if Result is Ok. Throws a Panic if the Result is Err, with the provided message.
override
expectErr(String message) → F
Returns the err value if Result is Err. Throws a Panic if the Result is Ok, with the provided message.
override
flatten() Result<S, F>

Available on Result<Result<S, F>, F>, provided by the FlattenExtension extension

Converts a Result of a Result into a single Result
inspect(void fn(S ok)) Ok<S, F>
If Ok, Calls the provided closure with the ok value, else does nothing.
override
inspectErr(void fn(F error)) Ok<S, F>
If Err, Calls the provided closure with the err value, else does nothing.
override
into<F2 extends Object>() Ok<S, F2>
Changes the Err type to F2. This is usually used when "this" is known to be an Ok and you want to return to the calling function, but the returning function's F type is different from this F type.
intoErr() → F

Available on Result<Never, F>, provided by the InfallibleErrExtension extension

intoOk() → S

Available on Result<S, Never>, provided by the InfallibleOkExtension extension

intoUnchecked<S2>() Ok<S2, F>
Changes the Ok type to S2. See into for a safe implementation of intoUnchecked. This is usually used when "this" is known to be an Err and you want to return to the calling function, but the returning function's Ok type is different from this Ok type.
override
isErr() bool
Returns true if the current result is an Err.
override
isErrAnd(bool fn(F)) bool
Returns true if the result is Err and the value inside of it matches a predicate.
override
isOk() bool
Returns true if the current result is a Ok.
override
isOkAnd(bool fn(S)) bool
Returns true if the result is Ok and the value inside of it matches a predicate.
override
iter() Iterable<S>
Returns an iterable over the possibly contained value. The iterator yields one value if the result is Ok, otherwise none.
override
map<W>(W fn(S ok)) Ok<W, F>
Returns a new Result, mapping any Ok value using the given transformation.
override
mapErr<W extends Object>(W fn(F error)) Ok<S, W>
Returns a new Result, mapping any Err value using the given transformation.
override
mapOr<W>(W defaultValue, W fn(S ok)) → W
Returns the provided default (if Err), or applies a function to the contained value (if Ok).
override
mapOrElse<W>(W defaultFn(F err), W fn(S ok)) → W
Evaluates the provided defaultFn (if Err), or applies a function to the contained value (if Ok).
override
match<W>({required W ok(S), required W err(F)}) → W
Returns the result of ok for the encapsulated value if this instance represents Ok or the result of err function for the encapsulated value if it is Err.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
or<F2 extends Object>(Result<S, F2> other) Result<S, F2>
Performs an "or" operation on the results. Returns the first Ok value, if neither are Ok, returns the other Err.
override
orElse<F2 extends Object>(Result<S, F2> fn(F)) Result<S, F2>
Calls fn if the result is Err, otherwise returns the Ok value of this.
override
toAnyhowResult() Result<S>

Available on Result<S, F>, provided by the BaseResultExtension extension

When this Result is a base base.Result and not already an "anyhow" Result, converts to anyhow Result. Otherwise returns this.
toAnyhowResult() Result<S>

Available on Result<S>, provided by the AnyhowResultExtensions extension

When this Result is a base base.Result and not already an "anyhow" Result, converts to anyhow Result. Otherwise returns this. Overrides the base Extension.
toAnyhowResult() Result<S>

Available on Ok<S, F>, provided by the BaseOkExtension extension

When this Result is a base base.Result and not already an "anyhow" Result, converts to anyhow Result. Otherwise returns this.
toFutureResult() FutureResult<S, F>

Available on Result<Future<S>, F>, provided by the ResultFutureToFutureResultExtension extension

Turns a Result of a Future into a FutureResult.
toFutureResult() FutureResult<S, F>

Available on Result<S, F>, provided by the ResultToFutureResultExtension extension

Turns a Result into a FutureResult.
toString() String
A string representation of this object.
override
transpose() Result<S, F>?

Available on Result<S?, F>, provided by the TransposeResultExtension extension

transposes a Result of a nullable type into a nullable Result.
unwrap() → S
Returns the ok value if Result is Ok. Throws a Panic if the Result is Err.
override
unwrapErr() → F
Returns the err value if Result is Err. Throws a Panic if the Result is Ok.
override
unwrapErrOr(F defaultValue) → F
Returns the encapsulated value if this instance represents Err or the defaultValue if it is Ok.
override
unwrapErrOrElse(F onOk(S ok)) → F
Returns the encapsulated value if this instance represents Err or the result of onError function for the encapsulated a Err value.
override
unwrapErrOrNull() → F?
Returns the err value if Result is Err, otherwise returns null. This can be used to determine is Ok or is Err, since when the failure type is not nullable, so a returned null value means this is not an Err. Same as "err()" in Rust, but "err" is a field name here
override
unwrapOr(S defaultValue) → S
Returns the encapsulated value if this instance represents Ok or the defaultValue if it is Err. Note: This should not be used to determine is Ok or is Err, since when the success type is nullable, a default value of null can be provided, which is ambiguous in meaning.
override
unwrapOrElse(S onError(F error)) → S
Returns the encapsulated value if this instance represents Ok or the result of onError function for the encapsulated a Err value. Note: This should not be used to determine is Ok or is Err, since when the success type is nullable, the value returned can be null, which is ambiguous in meaning.
override
unwrapOrNull() → S
Returns the value of Ok or null. Note: This should not be used to determine is Ok or is Err, since when the success type is nullable, a null is ambiguous in meaning.
override
withContext(Object fn()) Ok<S>

Available on Ok<S>, provided by the AnyhowOkExtensions extension

returns this
withContext(Object fn()) Result<S>

Available on Result<S>, provided by the AnyhowResultExtensions extension

If Result is Ok returns this. Otherwise, Lazily calls the function and returns an Error with the additional context. The context should not be an instance of Error.

Operators

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