iv-itertools
v0.1.1
Published
Attempt to port Python's itertools to JavaScript
Downloads
13
Maintainers
Readme
Itertools
Couple of functions to operate with collections/iterators.
Currently supported tools:
chain(iterable1, iterable2, ...)
see itertools.chainifilter(predicate, iterable)
see itertools.ifilterproduct(iterable1, iterable2, ..., repeat=1)
see itertools.producttoArray(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