Could you elaborate?
Achille Urbain
1

Basically, it’s a matter of giving an interface like reduce more power than it really deserves, leading to less strict usage, a much more complex type signature to understand, and sometimes even some unexpected behavior.

One simple example of unexpected behavior from extraneous arguments happens with how the native Array.map passes an index argument (along with a third and fourth argument), leading to some very unexpected behavior if the mapping function happens to, say, take an optional second argument:

[“3”,”3",”3",”3",”3",”3"].map(parseInt); //-> [3, NaN, NaN, NaN, 3, 3]

Strictly speaking, mapping functions, even for lists, don’t need to pass an index. That’s not even a thing that makes sense for all Functors, so the fact that Array’s map passes it makes it unlike most Functors, and thus less generalizable.

It’s the same for reduce: we can pile in some extra arguments with Arrays, but that makes the interface a little more tied to Arrays specifically (as opposed to other sorts of lists or other data types altogether) and also encourages us to make our reducing functions either more protected (against the additional arguments)/complex (using those extra arguments for more complex logic).

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.