Result<S, F extends Object> class sealed

Result is used for propagating errors and represents the sum type of Ok and Err.

S is the ok type (aka success) and F is an error (aka failure).

Implementers
Available extensions

Constructors

Result.new(_ResultEarlyReturnFunction<S, F> fn)
Creates a context for early return, similar to "Do notation". Here "$" is used as the "Early Return Key". when "$" is used on a type Err, immediately the context that "$" belongs to is returned with that Err. Works like the Rust "?" operator, which is a "Early Return Operator". e.g.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
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.
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.
andThenErr<W extends Object>(Result<S, W> fn(F error)) Result<S, W>
/ If Err, Returns a new Result by passing the Err value to the provided function.
copy() Result<S, F>
Performs a shallow copy of this result.
err() Option<F>
Converts a Result into an Option, returning Some with the err value if the Result is Err, and _None if the Result is Ok.
expect(String message) → S
Returns the ok value if Result is Ok. Throws a Panic if the Result is Err, with the provided message.
expectErr(String message) → F
Returns the err value if Result is Err. Throws a Panic if the Result is Ok, with the provided message.
flatten() Result<S, F>

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

Converts a Result of a Result into a single Result
inspect(void fn(S ok)) Result<S, F>
If Ok, Calls the provided closure with the ok value, else does nothing.
inspectErr(void fn(F error)) Result<S, F>
If Err, Calls the provided closure with the err value, else does nothing.
intoErr() → F

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

intoOk() → S

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

intoUnchecked<S2>() Result<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.
isErr() bool
Returns true if the current result is an Err.
isErrAnd(bool fn(F)) bool
Returns true if the result is Err and the value inside of it matches a predicate.
isOk() bool
Returns true if the current result is a Ok.
isOkAnd(bool fn(S)) bool
Returns true if the result is Ok and the value inside of it matches a predicate.
iter() Iter<S>
Returns an iterable over the possibly contained value. The iterator yields one value if the result is Ok, otherwise none.
map<W>(W fn(S ok)) Result<W, F>
Returns a new Result, mapping any Ok value using the given transformation.
mapErr<W extends Object>(W fn(F error)) Result<S, W>
Returns a new Result, mapping any Err value using the given transformation.
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).
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).
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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ok() Option<S>
Converts a Result into an Option, returning Some with the ok value if the Result is Ok, and _None if the Result is Err.
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.
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.
toFutureResult() FutureResult<S, F>

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

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

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

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

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

transposes a nullable Result into a non-nullable Result.
transpose() Result<S, F>?

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

transposes a Result of a nullable type into a nullable Result.
transpose() Option<Result<S, F>>

Available on Result<Option<S>, F>, provided by the Result$ResultOptionExtension extension

Transposes a Result of an Option into an Option of a Result.
unwrap() → S
Returns the ok value if Result is Ok. Throws a Panic if the Result is Err.
unwrapErr() → F
Returns the err value if Result is Err. Throws a Panic if the Result is Ok.
unwrapOr(S defaultValue) → S
Returns the encapsulated value if this instance represents Ok or the defaultValue if it is Err.
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.
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.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](_ResultEarlyReturnKey<F> op) → S
Functions an "Early Return Operator" when given an "Early Return key" "$". See Result.$ for more information.

Static Methods

async<S, F extends Object>(_AsyncResultEarlyReturnFunction<S, F> fn) Future<Result<S, F>>
Creates a async context for early return, similar to "Do notation". Here "$" is used as the "Early Return Key". when "$" is used on a type Err, immediately the context that "$" belongs to is returned with that Err. Works like the Rust "?" operator, which is a "Early Return Operator". e.g.