filter-arraylike-iterable
v0.1.5
Published
array like iterable decorated with filter method
Downloads
10
Readme
filter-arraylike-iterable
filter-arraylike-iterable
exports a class that, given an array-like iterable, builds iterables that provide filter method.
Install
$ npm install filter-arraylike-iterable --save
Usage
const FilterArrayLikeIterable = require('filter-arraylike-iterable')
const iterable = new FilterArrayLikeIterable([4, 2, 7, 8, 4, 3, 1]) // (4 7 4 1)
.filter(e => e % 3 === 1) // (4 7 8 7)
.filter(e !== 4) // (7 1)
// converting to array:
[...iterable] // [7, 1]
// traversing values:
for (const val of iterable) {
// ...
}
// creating an iterator that traverses the values
let iterator = iterable[Symbol.iterator]()
iterator.next() // {value: 7, done: false}
iterator.next() // {value: 1, done: false}
iterator.next() // {value: undefined, done: true}
// the same with string
const string = 'abcdef'
new FilterArrayLikeIterable(string) // ('a' 'b' 'c' 'd' 'e' 'f')
.filter(e => e !== 'c' || e !== 'e') // ('a' 'b' 'd' 'f')
// the same with typed array
const typedArray = new Uint8Array([128, 0, 0, 1])
new FilterArrayLikeIterable(naturals) // (128 0 0 1)
.filter(e => e !== 0) // (128 1)
Support
- Node.js >=6
- ES2015 transpilers
License
MIT