Skip to main content
These helpers let you work with multiple 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.
Iterable<Result<T, E>>
required
An array or iterable of results.
Result<T[], E>
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.
Iterable<PromiseLike<Result<T, E>>>
required
An array or iterable of ResultAsync values or promise-like results.
ResultAsync<T[], E>
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.
Iterable<Result<T, E>>
required
An array or iterable of results.
Result<T[], E[]>
Ok([...values]) or Err([...errors]).

chas.collectAsync(resultAsyncs)

The async counterpart to chas.collect. Concurrently awaits all inputs and collects every error.
Iterable<PromiseLike<Result<T, E>>>
required
An array or iterable of ResultAsync values or promise-like results.
ResultAsync<T[], E[]>
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.
Iterable<Result<T, E>>
required
An array or iterable of results.
Result<T, E[]>
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.
Iterable<PromiseLike<Result<T, E>>>
required
An array or iterable of ResultAsync values or promise-like results.
ResultAsync<T, E[]>
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.
Iterable<Result<T, E>>
required
An array or iterable of results.
Result<T, E>
The first result encountered.
Throws if called with an empty iterable. Always pass at least one result.

chas.raceAsync(resultAsyncs)

Returns a ResultAsync that settles with whichever input resolves first — the async equivalent of Promise.race.
Iterable<PromiseLike<Result<T, E>>>
required
An array or iterable of ResultAsync values or promise-like results.
ResultAsync<T, E>
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.
Record<string, ResultAsync<T, E> | PromiseLike<Result<T, E>>>
required
An object mapping string keys to async results.
ResultAsync<{ [K in keyof record]: T }, E>
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.
() => Generator | AsyncGenerator
required
A generator or async generator function that yields results via yield*.
Result<T, E> | ResultAsync<T, E>
The final return value wrapped in Ok, or the first Err that caused a short-circuit.
See the do-notation recipe for a deeper guide.