Created
August 27, 2012 17:31
-
-
Save pdex/3490634 to your computer and use it in GitHub Desktop.
iterator decorators / function composition
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
#!/usr/bin/python | |
import itertools | |
def iterchain( fn ): | |
def new( *iterables ): | |
return itertools.imap( fn, *iterables ) | |
return new | |
def itersink( fn ): | |
def new( *iterables ): | |
return map( fn, *iterables ) | |
return new | |
def it(): | |
return [1,2,3,4] | |
@iterchain | |
def do( i ): | |
return i * 2 | |
@itersink | |
def go( i ): | |
print i | |
if __name__ == '__main__': | |
go( do( it() ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment