drop-while-iterable

iterable class that provides dropWhile method

Usage no npm install needed!

<script type="module">
  import dropWhileIterable from 'https://cdn.skypack.dev/drop-while-iterable';
</script>

README

drop-while-iterable

travis ci npm version Coverage Status Dependency Status

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