transform-iterable
v0.2.10
Published
iterable that provides transformation methods for array iterables
Downloads
6
Readme
transform-iterable
transform-iterable
exports a class that builds iterables that provide map method.
Install
$ npm install transform-iterable --save
Usage
const TransformIterable = require('transform-iterable')
const iterable = new TransformIterable([4, 2, 7, 8]) // (4 2 7 8)
.map(e => 3 * e) // (12 6 21 24)
.filter(e => e % 4 !== 1) // (12 6 24)
.dropWhile(e => e % 12 === 0) // (6 24)
.takeWhile(e => e <= 12) // (6)
// converting to array:
[...iterable] // [6]
// traversing values:
for (const val of iterable) {
// ...
}
// creating an iterator that traverses the values
let iterator = iterable[Symbol.iterator]()
iterator.next() // {value: 6, done: false}
iterator.next() // {value: undefined, done: true}
Support
- Node.js >=6
- ES2015 transpilers
License
MIT