@iterables/roundrobin

given a set of iterables, take from each one in order until all are exhausted

Stats

StarsIssuesVersionUpdatedCreatedSize
@iterables/roundrobin
201.0.24 years ago4 years agoMinified + gzip package size for @iterables/roundrobin in KB

Readme

@iterables/roundrobin

Given a set of iterables, take from each one in order until all are exhausted.

const roundRobin = require('@iterables/roundrobin')

function * iter (what) {
  for (var i = 0; i < 2; ++i) {
    yield what
  }
}

for (const [idx, value] of roundRobin(iter('a'), iter('b'))) {
  console.log(idx, value) // 0 'a', 1 'b', 0 'a', 1 'b'
}

Installation

$ npm install --save @iterables/roundrobin

API

roundRobin(...iterables) -> Iterator<[index, T]>

Given iterables as args, return an iterator that takes from each given iterable in succession until all are exhausted, yielding a tuple of the index of the iterable and the item it took.

If iterables is uneven — say, one iterable has 2 items while another has 5 — after the first iterable is exhausted roundRobin will take exclusively from the second iterable.

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.