logoalt Hacker News

snackbrokenyesterday at 5:42 AM3 repliesview on HN

Map and Filter are nice because they let you reason locally about a single element in isolation. Reduce(Fold) forces you to reason globally about intermediate results. Reduce also forces you to conjure up a "zero" value of the relevant type, which isn't usually difficult but it does constitute some extra mental overhead.


Replies

sigbottletoday at 7:08 PM

Isn't reduce usually used for monoidal operations? Or do people implicitly absue ordering?

If the algortihm doesn't work the same forward, backwards, and with a tree scan, it ain't reduce (as a first approximation not IFF)

show 1 reply
mcphagetoday at 7:42 PM

> Reduce also forces you to conjure up a "zero" value of the relevant type, which isn't usually difficult but it does constitute some extra mental overhead.

It's always worthwhile to consider what the result will be when you pass in an empty list.

show 1 reply
mrkeentoday at 6:26 PM

It's pairwise, not global reasoning.

show 1 reply