This pipeline idea has actually been implemented further, see <http://
blog.onideas.ws/stream.py>.

from stream import map, filter, cut
range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]!
=25 and t[1]!=64) >> cut[1] >> list
[0, 1, 8, 27, 216, 343, 512, 729]

Wow, cool!

Just to show that you can easily add the iterator.map(f).blabla-syntax to Python:

    from __future__ import print_function

    class rubified(list):
        map    = lambda self, f: rubified(map(f, self))
        filter = lambda self, f: rubified(filter(f, self))
reject = lambda self, f: rubified(filter(lambda x: not f(x), self)) # each = lambda self, f: rubified(reduce(lambda x, y: print(y), self, None))
        def each(self, f):
            for x in self: f(x)

        def __new__(cls, value):
            return list.__new__(cls, value)

    def print_numbers():
        rubified([1, 2, 3, 4, 5, 6]).map(lambda n:
            [n * n, n * n * n]).reject(lambda (square, cube):
            square == 25 or cube == 64).map(lambda (square, cube):
            cube).each(lambda n:
            print(n))



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

Reply via email to