Sequential iteration and accumulation with explicit error handling.
Pipelean gives a clear contract to sequential operations: how items are processed, how state accumulates, and what happens when an operation fails. No hand-written loops, accidental error handling, or hidden failure policies.
Plain JavaScript. Eager execution. No framework or scheduler.
Sequential operations often require the same boilerplate: iterate over items, accumulate a value when needed, and decide what happens when an operation fails.
Pipelean makes these three concerns explicit, composable, and reusable.
import {series, collect} from 'pipelean'
const {results, errors} = await series(pages, importPage, {
strategy: collect,
onError: ({item, error}) => log.warn(item, error),
})
if (errors.length) report(errors)Process items sequentially, collect failures without losing successful results, and choose the error policy instead of burying it in a loop.
npm install pipeleanNode.js >= 22.7. ESM.
Pipelean is built around three concepts.
Process a sequence of independent items, one at a time.
| Function | Purpose |
|---|---|
series |
Process items, collect results and handle failures through a strategy |
filter |
Select items using a predicate |
series and filter support arrays, generators, and async iterables. They can process synchronous or asynchronous callbacks.
const {results, errors} = await series(items, processItem)Returning undefined from a mapper drops the item.
When each item depends on the result of the previous one, use a fold.
| Function | Keeps | Returns |
|---|---|---|
scan |
Every intermediate accumulator | Report with results |
reduce |
Final accumulator only | Report with value |
const {value: total} = await reduce(
tracks,
(sum, track) => sum + track.duration,
0,
)Use scan when intermediate states matter, and reduce when only the final state matters.
Errors are handled according to an explicit strategy. Strategies determine whether execution continues, stops, or throws.
| Strategy | Behavior |
|---|---|
collect |
Continue and collect errors in errors |
failLate |
Continue, then report failure after processing |
failFast |
Stop on the first error and return it as failure |
skip |
Continue without collecting errors |
rethrow |
Throw the original error immediately |
onError is an observation hook, not an error strategy.
Default strategies:
series,filter, andenrich:collectscanandreduce:failFast
Results make handled failures explicit. Use assertOk(result) when a failure must not be ignored.
See the error model in the Guide for result shapes, source errors, recovery, and strategy details.
These complement the core. You don't need them to get started.
pipe— compose value-in/value-out functions into a reusable pipeline.
mapSeries— sequential map with a fixedrethrowpolicy: returns a plain array or throws the original error.foldSync— synchronous fold with a fixedrethrowpolicy: returns the final accumulator or throws the original error. It isreduceSync(..., {strategy: rethrow}).value.enrich— accumulate object patches over one input.assign— build conditional property-assignment steps forenrich.- Sync counterparts —
seriesSync,filterSync,mapSeriesSync,scanSync,reduceSync,stopWhenSync,pipeSync,enrichSync, andtryCatchSync. They return directly and reject async-only behavior.
join— run a small set of named tasks concurrently and return a structured result.retry— retry a function after failure.stopWhen— stop an iterable when a predicate matches.forever— produce an unbounded sequence of ticks.
These are useful outside iteration and accumulation:
tryCatch— wrap a function with error handling and lifecycle hooks.assertOk— ensure a Pipelean result did not fail.where/findSync— predicate helpers and synchronous search.
- Not concurrent mapping. Iteration and accumulation are sequential.
joinis for a small set of heterogeneous tasks, not a concurrent collection. - Not lazy. Execution starts immediately.
- Not a stream adapter. Any iterable or async iterable is supported; Node streams need their own adapter.
- Not a replacement for simple native JavaScript. If a plain
map,filter,await, ortry/catchis clearer, use it.
- Guide — understand the mental model and how to choose the right operation.
- Reference — API signatures, options, return shapes, and exact contracts.
- Examples — practical usage.
- Patterns — recipes for common problems.
- ESLint plugin — lint rules and suggestions.
- Architecture — design principles.
- Migration — upgrading between versions.
- Alternatives — when another library owns the problem.
Pipelean includes an ESLint plugin that encourages explicit sequential processing and discourages common async mistakes.
import pipeleanConfig from 'pipelean/eslint/config'
export default [pipeleanConfig]See the ESLint documentation for configuration and individual rules.
Pipelean includes an Agent Skill for AI coding assistants.
npx skills add https://github.com/ildella/pipelean/tree/master/skills -g -ySee the repository's skills directory for details.
MIT