Result or ResultAsync values at once — collecting, racing, or combining them into a single result.
chas.all(results)
Returns Ok with an array of all values if every result is Ok, or short-circuits with the first Err encountered.
An array or iterable of results.
Ok([...values]) when all inputs are Ok, or the first Err.chas.allAsync(resultAsyncs)
The async counterpart to chas.all. Concurrently awaits all inputs and returns Ok with all values, or the first Err.
An array or iterable of
ResultAsync values or promise-like results.Resolves to
Ok([...values]) when all inputs are Ok, or the first Err.chas.collect(results)
Like chas.all, but does not short-circuit. Collects all errors instead of stopping at the first one. Returns Ok with all values if every result is Ok, or Err with an array of every error encountered.
Prefer this over chas.all in validation scenarios where you want to surface every failure at once.
An array or iterable of results.
Ok([...values]) or Err([...errors]).chas.collectAsync(resultAsyncs)
The async counterpart to chas.collect. Concurrently awaits all inputs and collects every error.
An array or iterable of
ResultAsync values or promise-like results.Resolves to
Ok([...values]) or Err([...errors]).chas.any(results)
Returns the first Ok encountered, or Err with an array of all errors if every result is Err. The inverse of chas.all.
An array or iterable of results.
The first
Ok, or Err([...errors]) if all inputs fail.chas.anyAsync(resultAsyncs)
The async counterpart to chas.any. Concurrently awaits all inputs and returns the first Ok, or all errors.
An array or iterable of
ResultAsync values or promise-like results.Resolves to the first
Ok, or Err([...errors]) if all inputs fail.chas.race(results)
Returns the first result in the iterable, regardless of whether it is Ok or Err. In synchronous contexts this is always the first element since inputs are evaluated left-to-right.
An array or iterable of results.
The first result encountered.
chas.raceAsync(resultAsyncs)
Returns a ResultAsync that settles with whichever input resolves first — the async equivalent of Promise.race.
An array or iterable of
ResultAsync values or promise-like results.Resolves with the first input to settle, whether
Ok or Err.chas.shapeAsync(record)
Concurrently awaits an object whose values are ResultAsync values and returns a single ResultAsync containing an object with the same keys mapped to their Ok values, or the first Err encountered. Use this to fan out parallel async operations with named keys.
An object mapping string keys to async results.
Resolves to a shaped object of all
Ok values, or the first Err.chas.go(generatorFn)
Do-notation for Result. Runs a generator function where each yield* result unwraps the Ok value or immediately short-circuits with the Err. This lets you write sequential, imperative-looking code without nested .andThen chains.
Pass a sync generator (function* () {}) to get a Result, or an async generator (async function* () {}) to get a ResultAsync. Yielding a ResultAsync inside a sync generator automatically upgrades the return type to ResultAsync.
A generator or async generator function that yields results via
yield*.The final return value wrapped in
Ok, or the first Err that caused a short-circuit.