
One of my students gave me an interesting question about why `filter` and `map` do not return a reusable function in case the iterable is not passed. With the current design ``` In [1]: a = filter(lambda x: x > 60) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-ad0178d4fce0> in <module> ----> 1 a = filter(lambda x: x > 60) TypeError: filter expected 2 arguments, got 1 ``` this is fine as long as you need to use that filter for once. But if you want to reuse it you either need to create the iterator every time specifying the filter function, or save the function in a var and create the filter with that. I'm wondering why can't we create custom filters and mappers that are reusable. The result will look something like this: ```
pass_filter = filter(lambda x: x > 60) foo = [42, 56, 67, 87] for i in pass_filter(foo): print(i) 67 86 bar = {45, 94, 65, 3} for i in pass_filter(bar): print(i) 65 94
Are there any drawbacks or limitations to this? Is is worth working on?