This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including blue-iterate
with all npm
packages installed. Try it out:
import { parallelMap, map, collect } from 'blue-iterate'
import got from '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')
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.