Function: bind()
Chains another Result-producing computation and merges its success value into the existing object under the specified key.
- If the original result is a Failure, it is returned as-is.
- If the next result is a Failure, it is returned as-is.
- If both are Success, a new object is returned by shallow-merging:
the original success object and
{ [name]: nextSuccess }.
This is useful for building up objects in a compositional and type-safe way, especially in validation or data-fetching pipelines.
Type Param
The key to assign the result of the fn computation.
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
bind<
N,R1,R2>(name,fn): (result) =>InferSuccess<R1> extendsobject?ResultFor<R1|R2, { [K in string | number | symbol]: K extends Exclude<keyof InferSuccess, N> ? InferSuccess[K] : InferSuccess<R2> },InferFailure<R1> |InferFailure<R2>> :unknown
Type Parameters
N
N extends string
R1
R1 extends ResultMaybeAsync<any, any>
R2
R2 extends ResultMaybeAsync<any, any>
Parameters
name
N
fn
(a) => R2
Returns
(
result):InferSuccess<R1> extendsobject?ResultFor<R1|R2, { [K in string | number | symbol]: K extends Exclude<keyof InferSuccess, N> ? InferSuccess[K] : InferSuccess<R2> },InferFailure<R1> |InferFailure<R2>> :unknown
Parameters
result
R1
Returns
InferSuccess<R1> extends object ? ResultFor<R1 | R2, { [K in string | number | symbol]: K extends Exclude<keyof InferSuccess, N> ? InferSuccess[K] : InferSuccess<R2> }, InferFailure<R1> | InferFailure<R2>> : unknown
Call Signature
bind<
N,F>(name,fn): <R1>(result) =>Parameters<F>[0] extendsobject?ResultFor<R1|ReturnType<F>, { [K in string | number | symbol]: K extends Exclude<keyof any[any], N> ? any[any][K] : InferSuccess<F> },InferFailure<R1> |InferFailure<F>> :unknown
Type Parameters
N
N extends string
F
F extends (a) => ResultMaybeAsync<any, any>
Parameters
name
N
fn
F
Returns
<
R1>(result):Parameters<F>[0] extendsobject?ResultFor<R1|ReturnType<F>, { [K in string | number | symbol]: K extends Exclude<keyof any[any], N> ? any[any][K] : InferSuccess<F> },InferFailure<R1> |InferFailure<F>> :unknown
Type Parameters
R1
R1 extends ResultMaybeAsync<Parameters<F>[0], any>
Parameters
result
R1
Returns
Parameters<F>[0] extends object ? ResultFor<R1 | ReturnType<F>, { [K in string | number | symbol]: K extends Exclude<keyof any[any], N> ? any[any][K] : InferSuccess<F> }, InferFailure<R1> | InferFailure<F>> : unknown
