you are viewing a single comment's thread
view the rest of the comments
[–] 18 points 1 month ago (1 child)

Reduce is harder to read. Maps and filters are deeply simple. The problem space a reduce can solve is, I'm pretty sure, strictly larger than both of them. Its generality is its downfall.

I'll happily use a reduce, but it has to be either as a well named function or immediately stored in a well named variable. If the reduce is complex enough that you can't name it, that's a smell to me, reach for a different tool.

  • source
  • hideshow 1 child comment
  • [–] 4 points 1 month ago

    Absolutely. I've used many reduces that I later regretted. It's powerful, but also too cryptic.

    And reduce has hidden performance risks. I've seen reduce used where the collector was assembled with a spread operator. But that's a loop within a loop, and can get very expensive. A simple forEach loop and just appending the new value in old fashioned ugly pedestrian imperative code, does not carry that risk.

  • source
  • parent