Function: orThrough()
Runs an additional computation using the error value of a Result or ResultAsync, but returns the original failure if the additional computation is successful.
If the original result is a Success, it is returned immediately without running the function. If the original result is a Failure, the function is executed with the error value. If the function returns a Success, the original failure is returned. If the function returns a Failure, that new failure is returned.
Useful for running error recovery or fallback logic while preserving the original error on success.
Type Param
The input Result or ResultAsync.
Type Param
The result type returned by fn.
Examples
See
pipe - It is recommended to use this function with the pipe function for better readability and composability.
Call Signature
orThrough<
R1,R2>(fn): (result) =>ResultFor<R1|R2,InferSuccess<R1>,InferFailure<R1> |InferFailure<R2>>
Type Parameters
R1
R1 extends ResultMaybeAsync<any, any>
R2
R2 extends ResultMaybeAsync<any, any>
Parameters
fn
(a) => R2
Returns
(
result):ResultFor<R1|R2,InferSuccess<R1>,InferFailure<R1> |InferFailure<R2>>
Parameters
result
R1
Returns
ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1> | InferFailure<R2>>
Call Signature
orThrough<
F>(fn): <R1>(result) =>ResultFor<R1|ReturnType<F>,InferSuccess<R1>,InferFailure<R1> |InferFailure<F>>
Type Parameters
F
F extends (a) => ResultMaybeAsync<any, any>
Parameters
fn
F
Returns
<
R1>(result):ResultFor<R1|ReturnType<F>,InferSuccess<R1>,InferFailure<R1> |InferFailure<F>>
Type Parameters
R1
R1 extends ResultMaybeAsync<any, Parameters<F>[0]>
Parameters
result
R1
Returns
ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1> | InferFailure<F>>
