Function: andThrough()
Runs an additional computation using the success value of a Result or ResultAsync, but returns the original result if the additional computation is successful.
If either the original result or the side effect result is a Failure, that failure is returned. Useful for running validations or side effects without altering the main result on success.
Type Param
R1
The input Result or ResultAsync.
Type Param
R2
The result type returned by fn.
Examples
Success Case
Failure Case (input is a Failure)
Failure Case (function returns a Failure)
See
pipe - It is recommended to use this function with the pipe function for better readability and composability.
Call Signature
andThrough<
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>>
Call Signature
andThrough<
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>>
