Res<S, F> extension type

The outcome of an operation that can fail: a Success or a Failure.

on

Constructors

Res.err(F value)
A Result holding the reason an operation failed.
Res.ok(S value)
A Result holding the value an operation produced.

Properties

asErr → F
The failure value. Throws if this is a Success.
no setter
asOk → S
The success value. Throws if this is a Failure.
no setter
isErr → bool
Whether this is a Failure.
no setter
isOk → bool
Whether this is a Success.
no setter

Methods

convert<S2>(S2 onOk(S ok)) → Res<S2, F>
Maps the success value. A failure passes through.
convertBoth<S2, F2>({required S2 onOk(S ok), required F2 onErr(F err)}) → Res<S2, F2>
Maps the success value and the failure value.
convertErr<F2>(F2 onErr(F err)) → Res<S, F2>
Maps the failure value. A success passes through.
ensure({required bool check(S ok), required F otherwise(S ok)}) → Res<S, F>
Turns a success that fails check into a failure of otherwise(success).
recoverWhen({required bool check(F err), required S then(F err)}) → Res<S, F>
Turns a failure that passes check into a success of then(failure).
resolve<T>({required T onOk(S ok), required T onErr(F err)}) → T
Folds both tracks into one value, mapping a success value or a failure value.