Created
July 11, 2018 01:30
-
-
Save btg5679/ffe53b3522abeb49ac11ea9844890899 to your computer and use it in GitHub Desktop.
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
function* favBeer() { | |
const reply = yield "What is your favorite type of beer?"; | |
console.log(reply); | |
if (reply !== "ipa") return "No soup for you!"; | |
return "OK, soup."; | |
} | |
{ | |
const it = favBeer(); | |
const q = it.next().value; // Iterator asks question | |
console.log(q); | |
const a = it.next("lager").value; // Question is answered | |
console.log(a); | |
} | |
// What is your favorite beer? | |
// lager | |
// No soup for you! | |
{ | |
const it = favBeer(); | |
const q = it.next().value; // Iterator asks question | |
console.log(q); | |
const a = it.next("ipa").value; // Question is answered | |
console.log(a); | |
} | |
// What is your favorite been? | |
// ipa | |
// OK, soup. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/btg5679/ffe53b3522abeb49ac11ea9844890899#file-favbeergenerator-js-L28
been