New submission from Vladimir Berkutov <dair.t...@gmail.com>: 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). ---------- components: Interpreter Core, Library (Lib) messages: 161935 nosy: dair-targ priority: normal severity: normal status: open title: map() and filter() methods for iterators type: enhancement versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14961> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com