0.1.1 • Published 8 years ago

iv-itertools v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Itertools

Build Status

Couple of functions to operate with collections/iterators.

Currently supported tools:

  • chain(iterable1, iterable2, ...) see itertools.chain
  • ifilter(predicate, iterable) see itertools.ifilter
  • product(iterable1, iterable2, ..., repeat=1) see itertools.product
  • toArray(iterable) unrolls an iterable to an array. If an argument is array by itself it'll be returned as is. Be sure that you are not passing infinite iterator.
  • makeIter(iterable) accepts iterable|subscriptable (Array, String, etc) data type and wraps it with explicit iterator object if required.
  • fuseIter(object, iterProvider) mixes in an iterator provider function. Uses Symbol.iterator if available.

Install

npm install Ostrovski/js-itertools

Usage

var chain = require('iv-itertools').chain;

// ES6
for (let el of chain([1, 2], [3, 4])) {
    console.log(el);  // 1 2 3 4
}

// ES5
var iter = chain([1, 2], [3, 4]);
var next = iter.next();
while (!next.done) {
    console.log(next.value);
    next = iter.next();
}

Test

npm run test