# Discussion on: ELI5 - "Map-filter-reduce"

Dimitar Venkov

for the sake of completeness, if we were interested in the total sum and are not concerned about making our code follow functional programming methods, we could rewrite the python one liner as:

sum(i*i for i in range(10) if not i % 2)

:)

Idan Arye

You don't have to ignore language constructs to "follow functional programming methods". In Haskell, for example, you can use the combinators:

``````Prelude> sum (map (\x -> x * x) (filter (\x -> x `mod` 2 == 0) [0..9]))
120
``````

Or you can use list comprehension(like in Python):

``````Prelude> sum [x * x | x <- [0..9], x `mod` 2 == 0]
120
``````

The second approach is also functional programming.

M. Shemayev

That single line explained more of map-filter-reduce than the articles I've been reading has! Not directed at the author, to be clear, it was a genuinely great article--I just have been puzzling over it because something has been tripping around in my brain and BAM, this comment did it. My bachelor's is in math and so the map-filter-reduce descriptions sounded so close and yet so far to what I kept almost thinking and that particular one-line tripped the right memory circuits!

Namc

Is there something I missed that I could have done better?

I tried to make it as simple as possible, and I'm sorry if it did not simplify things for you.