• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# stream-iterate
2
3Iterate through the values in a stream.
4
5```
6npm install stream-iterate
7```
8
9[![build status](http://img.shields.io/travis/mafintosh/stream-iterate.svg?style=flat)](http://travis-ci.org/mafintosh/stream-iterate)
10
11## Usage
12
13``` js
14var iterate = require('stream-iterate')
15var from = require('from2')
16
17var stream = from.obj(['a', 'b', 'c'])
18
19var read = iterate(stream)
20
21loop()
22
23// recursively iterates through each item in the stream
24function loop () {
25  read(function (err, data, next) {
26    console.log(err, data)
27    next()
28    loop()
29  })
30}
31```
32
33If you don't call `next` and call `read` again the same `(err, value)` pair will be returned.
34
35You can use this module to implement stuff like [a streaming merge sort](https://github.com/mafintosh/stream-iterate/blob/master/test.js#L5-L47).
36
37## License
38
39[MIT](LICENSE)
40