Skip to content

Instantly share code, notes, and snippets.

@pdex
Created August 27, 2012 17:31
Show Gist options
  • Save pdex/3490634 to your computer and use it in GitHub Desktop.
Save pdex/3490634 to your computer and use it in GitHub Desktop.
iterator decorators / function composition
#!/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