Message161935
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). |
|
Date |
User |
Action |
Args |
2012-05-30 08:59:54 | dair-targ | set | recipients:
+ dair-targ |
2012-05-30 08:59:54 | dair-targ | set | messageid: <1338368394.87.0.444048276529.issue14961@psf.upfronthosting.co.za> |
2012-05-30 08:59:54 | dair-targ | link | issue14961 messages |
2012-05-30 08:59:53 | dair-targ | create | |
|