accumulation — zipOrAccumulate & friends
Validation wants all the errors, not the first one. These
operations run every branch and concatenate the failures into a
NonEmptyList — Arrow 2.x's replacement for a separate
Validated type.
Lecture
Inside either<Nel<E>, _>(...) — any scope whose
error type is a NonEmptyList — the scope gains the
accumulation vocabulary:
r.zipOrAccumulate2..5(branches…, combine)— run N independent branches, report every failure, combine the successes.r.accumulate((acc) { … })— the general form: run branches withacc.accumulating(block), then read each result's.value. If anything failed, reading a value (or reaching the end of the block) raises the full error list.r.mapOrAccumulate(items, transform)— validate a whole collection fail-slow.r.bindNel(eitherNel)— unwrap anEitherNel, raising all of its errors at once;someEither.toEitherNel()bridges a fail-fast value in.
The contract is Arrow's: every branch runs (errors concatenate in branch order), a branch that throws instead of raising wins over accumulation, and after the first error successful results are no longer retained — iteration continues only to collect the remaining errors.
Demo 1 · zipOrAccumulate2
Demo 2 · accumulate — the general form
Demo 3 · mapOrAccumulate, bindNel & toEitherNel
Demo 4 · dependent — rules that read sibling values
A branch cannot read a sibling's Accumulated.value without
detonating — accumulation's one hard rule. But real validation has
dependent rules ("an expense needs a positive amount"),
which is why forms kept dropping down to a manual
if (!acc.hasErrors) guard. acc.dependent(block)
names that guard: the block runs only when every branch so far
succeeded — so sibling .value reads inside it are safe by
construction — and is skipped entirely otherwise. (No Arrow
counterpart; Arrow users hand-roll the same guard.)
Try it yourself
Exercise: finish both branches of signup so the second call
reports both failures.
NonEmptyList — the error carrier ·
Either × pipelines — fail-slow validation over fx() chains, with concurrency ·
either & Raise — the fail-fast scope this extends ·
typed errors — full guide