Skip to content

Instantly share code, notes, and snippets.

@maiah
Last active December 10, 2015 01:22
Show Gist options
  • Save maiah/1c21c2d83b55652ac490 to your computer and use it in GitHub Desktop.
Save maiah/1c21c2d83b55652ac490 to your computer and use it in GitHub Desktop.
Pokemon evolution with Javascript streams
'use strict';
const f = require('from');
const t = require('through');
const pokemons = f(['charmander', 'bulbasaur', 'squirtle']);
const evolve = t((pokemon) => {
'use strict';
let evolvedPokemon = pokemon;
switch (pokemon) {
case 'charmander':
evolvedPokemon = 'charmeleon'; break;
case 'bulbasaur':
evolvedPokemon = 'ivysaur'; break;
case 'squirtle':
evolvedPokemon = 'wartortle'; break;
}
this.emit('data', evolvedPokemon);
});
const deploy = t((pokemon) => {
console.log('Go', pokemon);
});
pokemons
.pipe(evolve)
.pipe(deploy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment