Package Exports
- streaming-iterables
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (streaming-iterables) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
streaming-iterables
A collection of utilities that work with sync and async iterables and iterators. Designed to replace your streams. Think some sort of combination of bluestream
and ramda but for a much more simple construct, async iterators. The goal is to make it dead easy to replace your stream based processes with async iterators, which in general should make your code smaller, faster and have less bugs.
Contributors welcome! I'd love to finish this release but I can't do it right now, so you're welcome to join the project and run with it.
Examples
const { parallelMap, map, collect } = require('streaming-iterables')
const got = require('got')
const pokeGenerator = async function* () {
let offset = 0
while(true) {
const url = `https://pokeapi.co/api/v2/pokemon/?offset=${offset}`
const { body: pokemon } = await got(url, { json: true })
if (pokemon.results.length > 0) {
offset += pokemon.results.length
for (const monster of pokemon.results) {
yield monster
}
} else {
return
}
}
}
const loadUrl = ({ url }) => got(url, { json: true }).then(resp => resp.body)
const loadPages = parallelMap(2, loadUrl)
const logMonsters = map(pokemon => console.log(pokemon.name, pokemon.sprites.front_default))
await collect(logMonsters(loadPages(pokeGenerator())))
console.log('caught them all')