-
-
Notifications
You must be signed in to change notification settings - Fork 11
V2: @ Home
This is the home of the previous version: 2.x.
stream-chain
bridges JavaScript functions with streams efficiently. It creates a chain of streams out of regular functions, asynchronous functions, generators, and existing streams, while properly handling backpressure. The resulting chain is represented as a Duplex stream, which can be combined with other streams in the usual way.
It is purpose is to simplify creating powerful object-processing pipelines. It eliminates a boilerplate helping to concentrate on functionality without losing the performance.
stream-chain
is a lightweight, no-dependencies micro-package. It is distributed under New BSD license.
Making processing pipelines appears to be easy: just chain functions one after another, and we are done. Real life pipelines filter objects out and/or produce more objects out of a few ones. On top of that, we have to deal with asynchronous operations, while processing or producing data: networking, databases, files, user responses, and so on. An unequal number of values per stage and unequal throughput of stages introduced problems like backpressure, which requires algorithms implemented by streams.
While many API improvements were made to make streams easy to use, in reality, a lot of boilerplate is required when creating a pipeline. stream-chain
eliminates many of them helping to keep your programs uncluttered and beautiful.
- Intro by examples — see what it can do!
- Chain — the heart of the package.
- Various useful helpers:
- Slicing utilities:
- take() — takes only a specified number of items from the stream. Can skip as well.
- takeWhile() — takes items while a condition is true.
- skip() — skips a specified number of items.
- skipWhile() — skips items while a condition is true.
- Fold AKA reduce:
- fold() — accumulates items using a supplied reducer function until its stream is finished, then produces a result.
- scan() — updates an accumulator with each item and passes a current value of the accumulator. It is a companion to fold().
- Reduce — a Writable stream that accumulates items just like fold(). The accumulator is available as a property on a stream's instance.
- Light-weight transducers:
- Slicing utilities: