Res<S, F> extension type

Represents a result that can either be successful or fail.

on

Constructors

Res.err(F value)
Represents a failed result.
Res.ok(S value)
Represents a successful result.

Properties

asErr → F
Returns the failure value of the result.
no setter
asOk → S
Returns the success value of the result.
no setter
isErr bool
Returns 'true' if the type is a failure, otherwise 'false'.
no setter
isOk bool
Returns 'true' if the type is a success, otherwise 'false'.
no setter

Methods

convert<S2>(S2 onOk(S ok)) Res<S2, F>
Converts the success type of the result.
convertBoth<S2, F2>({required S2 onOk(S ok), required F2 onErr(F err)}) Res<S2, F2>
Converts both the success and failure types of the result.
convertErr<F2>(F2 onErr(F err)) Res<S, F2>
Converts the failure type of the result.
ensure({required bool check(S ok), required F otherwise(S ok)}) Res<S, F>
Ensures that a success value satisfies a condition, otherwise converts it to a failure.
recoverWhen({required bool check(F err), required S then(F err)}) Res<S, F>
Recovers from a failure when a specified condition is met.
resolve<T>({required T onOk(S ok), required T onErr(F err)}) → T
Resolves the result into a single type.