functor-arraylike-iterable
v0.1.3
Published
Iterable that implements optimized map method for array-like iterables
Downloads
1
Readme
functor-arraylike-iterable
functor-arraylike-iterable
exports a class that builds iterables that provide map method.
Install
$ npm install functor-arraylike-iterable --save
Usage
const FunctorIterable = require('functor-arraylike-iterable')
const iterable = new FunctorIterable([4, 2, 7, 8]) // (4 2 7 8)
.map(e => 3 * e) // (12 6 21 24)
.map(e => e / 2) // (6 3 10.5 12)
// converting to array:
[...iterable] // [6, 3, 10.5, 12]
// 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: 3, done: false}
iterator.next() // {value: 10.5, done: false}
iterator.next() // {value: 12, done: false}
iterator.next() // {value: undefined, done: true}
Support
- Node.js >=6
- ES2015 transpilers
License
MIT