1.0.1 • Published 9 years ago

iterable-readable v1.0.1

Weekly downloads
136
License
MIT
Repository
github
Last release
9 years ago

Iterable-Readable

Turn an Array, iterable or generator into a readable stream:

Usage

var itStream = require('iterable-stream')

// An array:

itStream([1, 2, 3, 4, 5])
  .pipe(process.stdout)

// generator:

var arr = [1, 2, 3, 4, 5]

var i = 0
function* gen() {
  while (i < arr.length) {
    yield arr[i]
    i += 1
  }
}

itStream(gen)
  .pipe(process.stdout)

// iterable

itStream(gen())
  .pipe(process.stdout)

You can also pass a preprocessing function:

var arr = [1, 2, 3, 4, 5]

itStream([1, 2, 3, 4, 5], (val, next) => next(null, val * 2))
  .pipe(process.stdout) // => 2, 4, 6, 8, 10

Licence

MIT