combine
@sandlada/result/combine — combines many synchronous Results under two policies: fail first or accumulate every error.
- Operates on: arrays and tuples of
IResultOfT. - Execution model: synchronous, pure value combination with no callbacks.
- Not here: async combination (
promise-result/combine,async-result/combine), Option combination (option/all).
| Export | Description | Source |
|---|---|---|
combine |
Combines an array or tuple, returning the first Err or an Ok carrying all values. |
combine.ts |
all |
Combines a heterogeneous tuple, preserving each position’s type; returns the first Err. |
all.ts |
combineWithAllErrors |
Runs every input and accumulates all errors into Err(E[]). |
combineWithAllErrors.ts |
Contract notes
Section titled “Contract notes”combineandallareFailFirst: they keep the first error and never touch the remaining inputs.combineWithAllErrorsisAccumulateand visits every input.- An empty input returns
Ok([])for all three. This is an intentional divergence fromoption/all, which rejects the empty tuple at the type level. combinehas two overloads: a heterogeneous tuple form and a homogeneous array form (IResultOfT<A, E>[]→IResultOfT<A[], E>).- Nothing here throws; there are no callbacks to capture.
- Throw and short-circuit policy: behavior-modes.md §4.3.
Related
Section titled “Related”primitives—sequencedelegates tocombine.promise-resultandasync-result— async combination with the same two policies.option— the Option-sideallandzipWith.