thunk (2007-02-07)
index
/home/ping/web/python/thunk.py

Shorthand syntax for making thunks.
 
Use _ as a placeholder in an expression to create a one-argument
function that fills in the placeholder and evaluates the expression.
For example:
 
    >>> from thunk import _
    >>> numbers = [3, 8, 4, 1, 2]
    >>> filter(_ < 5, numbers)
    [3, 4, 1, 2]
    >>> map(_ + 7, numbers)
    [10, 15, 11, 8, 9]
    >>> words = 'lovely spam and eggs'.split()
    >>> filter(_.endswith_('s'), words)
    ['eggs']
    >>> 
 
Notice that when calling a method on _ you need to append an
underscore to the method name (in order to distinguish a method
call from an attribute lookup.
 
The illusion is far from complete, but it's a fun hack.

 
Classes
       
CallThunk
Thunk

 
class CallThunk
     Methods defined here:
__call__(self, *args, **kw)
__init__(self, thunk, name)

 
class Thunk
     Methods defined here:
__add__(self, other)
__call__(self, target)
__div__(self, other)
__eq__(self, other)
__ge__(self, other)
__getattr__(self, other)
__getitem__(self, other)
__gt__(self, other)
__init__(self, thunk=<function identity>)
__le__(self, other)
__lt__(self, other)
__mul__(self, other)
__ne__(self, other)
__sub__(self, other)

 
Functions
       
identity(x)

 
Data
        __author__ = 'Ka-Ping Yee'
__date__ = '2007-02-07'

 
Author
        Ka-Ping Yee