Skip to content

feat: add Traversable utilities - #599

Open
ghoullier wants to merge 1 commit into
mainfrom
ghoullier-feat-traversable
Open

feat: add Traversable utilities#599
ghoullier wants to merge 1 commit into
mainfrom
ghoullier-feat-traversable

Conversation

@ghoullier

Copy link
Copy Markdown
Owner

Summary

Add Traversable utilities that enable inverting nested structures like Array<Option<T>> into Option<Array<T>> for fail-fast collection processing.

What's included

  • traverse — maps each element through a function returning Option, collecting results into Option<R[]> (returns None if any element fails)
  • sequence — specialization of traverse with identity, flipping Option<T>[] into Option<T[]>
  • traverseResult — same concept for Result: returns Ok of array if all succeed, or the first Error
  • sequenceResult — flips Result<T, E>[] into Result<T[], E>

Why

Traversable is a fundamental FP pattern for working with collections of effectful computations. Instead of manually iterating and checking each result, these utilities provide a declarative way to "fail fast" when processing arrays where each element may succeed or fail.

Add traverse, sequence, traverseResult, and sequenceResult functions
that invert nested structures (e.g., Array<Option<T>> → Option<Array<T>>)
for fail-fast collection processing.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant