slice-iterable

0.1.3 • Public • Published

slice-iterable

travis ci npm version Coverage Status Dependency Status

slice-iterable exports a class that builds iterables that provide slice method.

Install

$ npm install slice-iterable --save

Usage

const SliceIterable = require('slice-iterable')

const iterable = new SliceIterable(new Set([4, 2, 7, 8, 4, 7])) // (4 2 7 8 4 7)
    .slice(0, 5) // (4 2 7 8 7)
    .slice(2, 5) // (7 8 7)
    .slice(1, 2) // (8)

// converting to array:
[...iterable] // [8]

// traversing values:
for (const val of iterable) {
    // ...
}

// creating an iterator that traverses the values
let iterator = iterable[Symbol.iterator]()
iterator.next() // {value: 8, 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...)

new SliceIterable(naturals) // (1 2 3 4 5 6 7 8 9...)
    .slice(3, 8) // (4 5 6 7 8)

Support

  • Node.js >=6
  • ES2015 transpilers

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i slice-iterable

Weekly Downloads

3

Version

0.1.3

License

MIT

Last publish

Collaborators

  • xgbuils