add Collect: run every validator and join all errors #10

Merged
aneurin merged 1 commits from add-collect into main 2026-09-07 12:50:51 +00:00
Member

Closes #5.

Adds Collect — the all-errors-at-once counterpart to All:

v := Collect(MinLength(8), Chars("a-z0-9"), NotIn("password"))
err := v(input) // every failure, not just the first
  • All is unchanged — same signature, still stops at the first failure. Collect is a separate function so nothing about All moves (this was the fast bool idea; it would have broken All's signature and every call site, including zampler/internal/database/files.go).
  • Collect runs every validator and returns the failures joined with errors.Join. errors.Is still matches each contained error, so errors.Is(err, ErrDisallowedChars) works whether one rule failed or five did. Zero failures → nil.
  • No new dependencies (errors.Join is stdlib, Go 1.20+).

New files only: collect.go, collect_test.go (table subtests + a runnable ExampleCollect). go vet + go test ./... green.

🤖 Generated with Claude Code

Closes #5. Adds `Collect` — the all-errors-at-once counterpart to `All`: ```go v := Collect(MinLength(8), Chars("a-z0-9"), NotIn("password")) err := v(input) // every failure, not just the first ``` - `All` is **unchanged** — same signature, still stops at the first failure. `Collect` is a separate function so nothing about `All` moves (this was the `fast bool` idea; it would have broken `All`'s signature and every call site, including `zampler/internal/database/files.go`). - `Collect` runs every validator and returns the failures joined with `errors.Join`. `errors.Is` still matches each contained error, so `errors.Is(err, ErrDisallowedChars)` works whether one rule failed or five did. Zero failures → `nil`. - No new dependencies (`errors.Join` is stdlib, Go 1.20+). New files only: `collect.go`, `collect_test.go` (table subtests + a runnable `ExampleCollect`). `go vet` + `go test ./...` green. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added 1 commit 2026-09-07 12:47:52 +00:00
Collect is the all-errors-at-once counterpart to All. All still stops at
the first failure (unchanged); Collect runs every function and returns the
failures joined with errors.Join, which errors.Is still matches element by
element. Kept as a separate function rather than a flag on All so All's
signature and behaviour don't change.

Closes #5

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
aneurin merged commit e65d7d66c1 into main 2026-09-07 12:50:51 +00:00
aneurin deleted branch add-collect 2026-09-07 12:50:52 +00:00
Sign in to join this conversation.