drop-while-iterable
v0.2.0
Published
iterable class that provides dropWhile method
Downloads
4
Readme
drop-while-iterable
drop-while-iterable
exports a class that builds iterables that provide dropWhile method.
Install
$ npm install drop-while-iterable --save
Usage
const I = require('drop-while-iterable')
const first = I.of(new Set([4, 2, 7, 8, 4, 7])) // (4 2 7 8 4 7)
const second = I.dropWhile(e => e % 2 === 0, first) // (7 8 4 7)
const third = I.dropWhile(e => e > 5, second) // (4 7)
// converting to array:
[...third] // [4 7]
// traversing values:
for (const val of third) {
// ...
}
// creating an iterator that traverses the values
let iterator = third[Symbol.iterator]()
iterator.next() // {value: 4, done: false}
iterator.next() // {value: 7, done: false}
iterator.next() // {value: undefined, done: true}
// Infinite iterable
const naturals = {
[Symbol.iterator]: function* () {
let i = 1
while(true) { yield i++ }
}
} // (1 2 3 4...)
I.dropWhile(e => e > 5, I.of(naturals)) // (6 7 8 9 10...)
Support
- Node.js >=6
- ES2015 transpilers
License
MIT