homepage

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 <1338368394.87.0.444048276529.issue14961@psf.upfronthosting.co.za>
In-reply-to
Content
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
 else:
 continue
Introduction of such methods will allow to transform collections lazy without significant memory consumption (as was mentioned in http://bugs.python.org/issue912738).
History
Date User Action Args
2012年05月30日 08:59:54dair-targsetrecipients: + dair-targ
2012年05月30日 08:59:54dair-targsetmessageid: <1338368394.87.0.444048276529.issue14961@psf.upfronthosting.co.za>
2012年05月30日 08:59:54dair-targlinkissue14961 messages
2012年05月30日 08:59:53dair-targcreate

AltStyle によって変換されたページ (->オリジナル) /