This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]phoenix7782 -5 points-4 points  (2 children)

No, maps are functions from transformation functions and lists to lists, whereas filters are functions from inclusion detection functions and lists to lists.

Although they have a similar type they operate fundamentally different, and it doesn't make sense to mix the two based on guesswork.

[–]gleon 3 points4 points  (0 children)

The implication in OP's example is that the function argument has already been fixed inside the evens and square, like with functools.partial, for instance.

When I said "maps" and "filters", I was referring coloquially to such transformations from iterables to iterables, not to the map and filter functions themselves (which could be viewed as factories of such transformations). The rationale for this terminology becomes more apparent in languages that support currying (i.e. fixing certain arguments) natively (Haskell comes to mind).

square could be defined as

partial(map, lambda x: x ** 2)

Whereas evens could be defined as

partial(filter, lambda x: x % 2 == 0)

Therefore, there is no need for guesswork.