Add basic arithmetic to Math

# Angus Croll (13 years ago)

Rationale:

Some functional JavaScript idiomstwitter.com/skilldrick/status/211868188806352896are

hamstrung by the lack of native basic arithmetic functions. Would be handy/elegant/instructive to be able to write

arr.reduce(Math.add);

Moreover having functional versions of arithmetic operators would improve the currying/partial/composition experience.

Caveats:

  1. Arrow functions work pretty well too: arr.reduce((a,b)=>a+b);

  2. If add and multiply accepted multiple args, reduce would not be necessary for these cases: Math.add.apply(null, arr);

# Allen Wirfs-Brock (13 years ago)

On Jun 10, 2012, at 11:48 AM, Angus Croll wrote:

Rationale:

Some functional JavaScript idioms are hamstrung by the lack of native basic arithmetic functions. Would be handy/elegant/instructive to be able to write

arr.reduce(Math.add);

Moreover having functional versions of arithmetic operators would improve the currying/partial/composition experience.

Caveats:

  1. Arrow functions work pretty well too: arr.reduce((a,b)=>a+b);

These seems better, non-invasive approach rather than than adding built-in functions corresponding to every built-in operator.

Also, nothing preventing somebody from creating a library of such functions.

  1. If add and multiply accepted multiple args, reduce would not be necessary for these cases: Math.add.apply(null, arr);

Math.add(...arr)

# Nadav Shesek (13 years ago)

On Jun 11, 2012 6:18 PM, "Allen Wirfs-Brock" <allen at wirfs-brock.com> wrote:

On Jun 10, 2012, at 11:48 AM, Angus Croll wrote:

Rationale:

Some functional JavaScript idioms are hamstrung by the lack of native

basic arithmetic functions.

Would be handy/elegant/instructive to be able to write

arr.reduce(Math.add);

Moreover having functional versions of arithmetic operators would

improve the currying/partial/composition experience.

Caveats:

  1. Arrow functions work pretty well too: arr.reduce((a,b)=>a+b);

These seems better, non-invasive approach rather than than adding

built-in functions corresponding to every built-in operator.

Also, nothing preventing somebody from creating a library of such

functions.

gkz/prelude-ls, also supports currying which is quite useful

  1. If add and multiply accepted multiple args, reduce would not be

necessary for these cases: