1.0.6 • Published 11 years ago

chain-stream v1.0.6

Weekly downloads
3
License
-
Repository
github
Last release
11 years ago

chain-stream

Chain stream operations together

Example

The result of chain is a stream at every step. In addition to being a stream it has the methods demonstrated below

var chain = require("..")
    , from = require("read-stream").fromArray

// Creates a stream from an array
// You can also pass any readable stream in
chain([1,2,3,4,5])
    // [1, 2, 3, 4, 5]
    .log("initial state")
    // Map every chunk of data flowing through the stream to something else
    .map(function (x) { return x * 5 })
    // [5, 10, 15, 20, 25]
    .log("mapped state")
    // Filter the stream by dropping chunks you don't care about
    .filter(function (x) { return x % 2 })
    // [5, 15, 25]
    .log("filtered state")
    // Accumulate state about the stream
    .reductions(function (acc, x) { return acc + x }, 0)
    // [5, 20, 45]
    .log("reducted state")
    // Map the each chunk to a stream. This becomes a stream of streams
    .map(function (x) { return from([x, x * 2, x * 3]) })
    // Flatten the stream of streams into a single stream
    .flatten()
    .value(function (state) {
        // [5, 10, 15, 20, 40, 60, 45, 90, 135]
        console.log("final state", state)
    })

log and value are just utility methods that make the debugging easier.

Installation

npm install chain-stream

Contributors

  • Raynos

MIT Licenced

1.0.6

11 years ago

1.0.5

12 years ago

1.0.4

12 years ago

1.0.3

12 years ago

1.0.2

12 years ago

1.0.1

12 years ago

1.0.0

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago