High Order Messages in Python
Sam Pointon
free.condiments at gmail.com
Sat Oct 22 18:35:41 EDT 2005
This can be suitably applied to Python with the use of Higher Order
Functions, though. It's not quite the Ruby version because Python
allows you to use functions as first-class objects, complicating the
All-You-Can-Do-Is-Pass-A-Message philosophy. This is my 5-minute
implementation:
class HigherOrderList(list):
def do(self, func):
return HigherOrderList(each(self, func))
def where(self, pred):
return HigherOrderList(mass_test(self, pred))
def mass_test(iterable, pred):
for item in iterable:
if pred(item):
yield item
def each(iterable, method):
for item in iterable:
yield method(item)
More information about the Python-list
mailing list