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)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to