This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dair-targ
Recipients dair-targ
Date 2012-05-30.08:59:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It might be useful to introduce a new map() and filter() methods to iterators and iterables. Both methods should accept lambda/function which transforms a single argument into value. Both methods should return another iterator.

# proposed methods usage:
range(10).map(abs).filter(lambda x: x % 5 == 0)
# existing equivalent:
filter(lambda x: x % 5 == 0, map(abs, range(-10, 10)))
# result:
[10, 5, 0, 5]

Rough equivalent of implementation:
class iterator:
    def map(self, fn):
        for v in self:
            yield fn(v)
    def filter(self, fn):
        for v in self:
            if fn(v):
                yield v

Introduction of such methods will allow to transform collections lazy without significant memory consumption (as was mentioned in
Date User Action Args
2012-05-30 08:59:54dair-targsetrecipients: + dair-targ
2012-05-30 08:59:54dair-targsetmessageid: <>
2012-05-30 08:59:54dair-targlinkissue14961 messages
2012-05-30 08:59:53dair-targcreate