Created
August 7, 2018 19:54
-
-
Save theelous3/2b5a9b6909bd5e787877aad2013ae0ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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 processor(burn=1): | |
def inner(gen): | |
def wrapper(*args, **kwargs): | |
g = gen(*args, **kwargs) | |
for _ in range(burn): | |
next(g) | |
return g | |
return wrapper | |
return inner | |
from itertools import count | |
# say we want to skip the first 99 elements of our generator | |
@processor(99) | |
def blah(): | |
yield from count() | |
next(blah()) + sum(map(ord, 'lol')) | |
# or we want to init something that processes things infinitely without | |
# an ugly blank next() call before we start to gen.send() | |
@processor() | |
def decode_or_some_shit(encoding='utf-8'): | |
buffer = b'' | |
while True: | |
buffer = yield buffer | |
buffer = buffer.decode(encoding) | |
decoder = decode_or_some_shit() | |
decoder.send(b'lololol toot toot') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment