Error Accumulation
validate and partition execute every Effect in a collection even after earlier items fail with typed errors. Reach for validate when any error must fail the batch with all problems reported, and partition when valid outputs should survive alongside rejected ones.
| Combinator | Success type | Error channel E | When to use |
|---|---|---|---|
validate | A[] | [E, ...E[]] | All items must pass, or report every error |
validate(..., { discard: true }) | void | [E, ...E[]] | Check validity without retaining outputs |
partition | [A[], E[]] | never | Keep valid results and inspect failures together |
Validating every computation
error InvalidHandle {
input: string
}
effect function validateHandle(input: string) {
const handle = input.trim()
if (handle.length < 3) throw new InvalidHandle({ input })
return handle.toLowerCase()
}
effect function validateTeam() {
return try validate(
["Jo", "RIVER", ""],
(input) => validateHandle(input),
{ concurrency: 2 }
)
}
// string[]![InvalidHandle, ...InvalidHandle[]]
// Run in an effect function:
// try Console.log(try validateHandle(" RIVER "))
// {
// const jsonValue = (try flip(validateTeam())).map((error) => error.input)
// try Console.log(try Effect.try(() => JSON.stringify(jsonValue)))
// }river
["Jo",""]validate runs every element despite typed failures. If any element fails, E receives a nonempty array of all domain errors and successes are discarded; otherwise it succeeds with every result.
effect function checkTeamOnly() {
try validate(["RIVER", "SKY"], (input) => validateHandle(input), {
discard: true,
concurrency: 2
})
}
// Run in an effect function:
// try checkTeamOnly()
// try Console.log("All handles valid")All handles validPass { discard: true } to return void on success when only validation matters, and { concurrency } to bound parallel checks. A cause without an expected failure still aborts execution. Both APIs convert errors with Effect's result policy: a cause containing a defect propagates with its expected failures as defects, and an expected failure beside an interruption narrows to the failure and drops the interruption—inspect the full cause when cancellation must be preserved.
Partitioning successes and failures
effect function inspectTeam() {
const [handles, errors] = try partition(
["Jo", "RIVER", ""],
(input) => validateHandle(input),
{ concurrency: 2 }
)
return {
handles, // ["river"]
rejected: errors.length // 2
}
}
// { handles: string[]; rejected: number }!!
// Run in an effect function:
// {
// const jsonValue = try inspectTeam()
// try Console.log(try Effect.try(() => JSON.stringify(jsonValue)))
// }
// Output: {"handles":["river"],"rejected":2}partition returns [successes, failures] and removes expected errors from E, letting callers keep valid entries while reporting rejections. Its handling of defects and mixed causes matches validate.
Coming from Effect
Pass validate or partition a callback returning an Effect—a plain arrow when forwarding an existing Effect, or an effect arrow when the body runs Effects directly. Array .map only builds an array of unexecuted Effects without running them.
The matching Effect page: effect.website/docs/v4/error-management/error-accumulation