DEV Community

loading...

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

Collapse
idanarye profile image
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.