Last active
November 16, 2018 21:04
-
-
Save badgateway666/1c154c29361d11db6212574e0151457b to your computer and use it in GitHub Desktop.
Generators <3
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
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