Last active
December 10, 2015 01:22
-
-
Save maiah/1c21c2d83b55652ac490 to your computer and use it in GitHub Desktop.
Pokemon evolution with Javascript streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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