split-iterable
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i split-iterable

Weekly Downloads

1

Version

0.1.8

License

MIT

Unpacked Size

3.17 kB

Total Files

5

Last publish

Collaborators

  • khai96_