Skip to content

Instantly share code, notes, and snippets.

@badgateway666
Last active November 16, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badgateway666/1c154c29361d11db6212574e0151457b to your computer and use it in GitHub Desktop.
Save badgateway666/1c154c29361d11db6212574e0151457b to your computer and use it in GitHub Desktop.
Generators <3
def PromptUser(prompt):
yield input(prompt)
def LoopGen(gen, *args, **kwargs):
while True:
for item in gen(*args, **kwargs):
yield item
def FilterGen(gen, pattern):
for filterItem in gen:
if filterItem == pattern:
yield filterItem
prompt = PromptUser
pipeline = LoopGen(prompt, "Think about it: ")
pipeline = FilterGen(pipeline, "HOLY SHIT!")
for item in pipeline:
print("Absolutely: ", item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment