‹ BackHN Continuity

Thread

Anecdotally, programmers dislike "reduce"

175 points · 283 comments · vinhnx

  1. RomanKornev · · focus · HN ↗
    Every single `reduce` can be replaced with a more intuitive `groupBy`, `partition`, `mapValues`, `keyBy`, etc.

    Reduce can approximate anything, that doesn't mean we should use it.

    My favorite antipattern is

      items.reduce(
        (acc, item) => ({
          ...acc,
          [item.id]: item,
        }), {}
      );
    
    Like, why? Not only is this ridiculously inefficient O(N^2), it's also longer and less understandable than "build a new map" version.
    1. tehnub · · focus · HN ↗
      This one doesn't seem expressible in those terms:

          from functools import reduce
      
          df = reduce(DataFrame.union, dfs)
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.