@agen/batch

0.1.0 • Public • Published

@agen/batch

Transform individual items from parent generator to a sequence of arrays of the specified size.

This method accepts the following parameters:

  • generator - asynchronous generator providing inidvidual elements
  • batchSize - size of returned batches; default value is 10

It returns an asynchronous generator providing element batches (arrays)
of the specified size.

Example:

const batch = require('@agen/batch');

...
const list = [
  'item-0',
  'item-1',
  'item-2',
  'item-3',
  'item-4',
  'item-5',
  'item-6',
  'item-7'
]
for await (let b of batch(list, 3) {
  console.log('-', b);
}
// Will print
// - ['item-0', 'item-1', 'item-2']
// - ['item-3', 'item-4', 'item-5']
// - ['item-6', 'item-7']

Readme

Keywords

none

Package Sidebar

Install

npm i @agen/batch

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

1.97 kB

Total Files

5

Last publish

Collaborators

  • mkotelnikov