Hacker News new | past | comments | ask | show | jobs | submit
Sure, I'm up for some bike-shedding. [0][1] Unless performance demands otherwise, I prefer map+filter because:

1. It's cheaper/faster at communicating intent to humans reading your code. Since a reduce call can do all sorts of interesting things, people need to stare harder to realize "oh, it's just doing a a map and filter together."

2. Things are easier to debug. I can vet the process of transformation (and its intermediate results) and then vet the process of excluding some of those results.

_____

With respect to debugging, a sample form Elixir's REPL where the piping (|>) to the dbg() function reveals the intermediate state:

    iex(1)> [5,34,6,2,7,3,1] |> 
                     Enum.map(fn x -> x * x end) |>
                     Enum.filter(fn x -> x < 10 end) |> 
                     dbg()

    [iex:4: (file)]
    [5, 34, 6, 2, 7, 3, 1] #=> [5, 34, 6, 2, 7, 3, 1]
    |> Enum.map(fn x -> x * x end) #=> [25, 1156, 36, 4, 49, 9, 1]
    |> Enum.filter(fn x -> x < 10 end) #=> [4, 9, 1]


[0] https://en.wikipedia.org/wiki/Law_of_triviality

[1] https://www.smbc-comics.com/comic/noun