paramap-it

0.1.1 • Public • Published

paramap-it

Build Status dependencies Status JavaScript Style Guide

Parallel mapping for async iterators

You have an async transform you need to apply to the values you get from an iterable, but want to apply these transforms in parallel and retain the original ordering.

Install

npm i paramap-it

Usage

const paramap = require('paramap-it')
const pause = ms => new Promise(resolve => setTimeout(resolve, ms))
 
const source = [1, 2, 3, 4, 5] // Can be ANY iterable or async iterable
 
// Asynchronously double the values from the source iterable IN PARALLEL
const doubler = paramap(source, async value => {
  await pause(Math.random())
  return value * 2
})
 
for await (const value of doubler) {
  console.log(value)
}
 
// Logs:
// 2
// 4
// 6
// 8
// 10
// Note: order is retained

API

const paramap = require('paramap-it')

paramap(source, mapper, [options])

Returns a new async iterable that can be used to consume the source iterable, applying the async mapper function to each item.

  • source (async Iterable) - Iterable or AsyncIterable to map data from
  • mapper (async Function) - Function that receives one parameter, the value to be mapped, and should return a Promise that resolves to the mapped value
  • options.ordered (Boolean default true) - set to false to discard ordering and yield values as soon as they are resolved (more performant)

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    2,820
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    2,820
  • 0.1.0
    0

Package Sidebar

Install

npm i paramap-it

Weekly Downloads

2,820

Version

0.1.1

License

MIT

Unpacked Size

11.1 kB

Total Files

6

Last publish

Collaborators

  • alanshaw