r/coding • • 18d ago

Anecdotally, programmers dislike "reduce"

https://evanhahn.com/posts/2026-09-13-programmers-dislike-reduce/
136 Upvotes

77 comments sorted by

View all comments

Show parent comment

8

u/thussy-obliterator 17d ago edited 17d ago

fold with monoids isn't too bad, but yeah once your f breaks associativity things get way more confusing, then you gotta worry about which fold it is, and which param of the combinator is the accumulator

1

u/tdammers 17d ago

Even with monoids, you still have the additional mental burden of tracking not only the current list element in your head, but also a quasi-stateful accumulator value (in foldr :: (b -> a -> b) -> b -> [a] -> b, the b type is the accumulator, a is the list element type); with map and filter, the "accumulator" is just a list we build up as we go, and we never worry about the previous elements while evaluating the current.