0.1.8 • Published 4 years ago

split-iterable v0.1.8

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Split Iterable

Split iterable into multiple chunks

Usage

splitIterable

const { splitIterable } = require('split-iterable')

expect(Array.from(
  splitIterable([0, 'x', 1, 2, 'x', 3, 4, 5])
)).toEqual([
  [0],
  [1, 2],
  [3, 4, 5]
])

splitAsyncIterable

const { splitAsyncIterable } = require('split-iterable')

const iterable = {
  async * [Symbol.asyncIterator] () {
    yield * [0, 'x', 1, 2, 'x', 3, 4, 5]
  }
}

async function toArray (iterable) {
  let array = []

  for await (const item of iterable) {
    array.push(item)
  }

  return array
}

expect(await toArray(
  splitAsyncIterable(iterable)
)).toEqual([
  [0],
  [1, 2],
  [3, 4, 5]
])

License

MIT © Hoàng Văn Khải

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago