Swift style syntax

Michael Luder-Rosefield rosyatrandom at gmail.com
Tue May 7 11:33:18 UTC 2019


--------------------------
Dammit babies, you've got to be kind.


On Tue, 7 May 2019 at 05:58, Ates Goral <ates at magnetiq.com> wrote:

> This topic has been discussed a long time ago and has stalled on
> discussions of a standard library.
>
> Coming back to the idea of adding some basic math operations directly
> on Math, there could be value in adding at least the following (from
> Isiah Meadows's post):
>
> > - `a + b` -> `Math.add` -> `:+`
> > - `a - b` -> `Math.sub` -> `:-`
> > - `a * b` -> `Math.mul` -> `:*` (different from `imul`)
> > - `a / b` -> `Math.div` -> `:/`
>
> `Math.add`: Among potentially other things, this could be useful for
> an out-of-the-box, terse way to add up items in an array. So, instead
> of:
>
> ```
> array.reduce((sum, item) => sum + item);
> ```
>
> Items could be added up with:
>
> ```
> array.reduce(Math.add);
> ```
>
> `Math.sub`: Among potentially other things, this could be useful for
> sorting numbers without having to define a custom comparator (i.e. almost
> as
> an out-of-the-box riposte to the "JavaScript WTF" refrain of
> lexicographically sorting numbers by using the default sort
> implementation.) So, instead of:
>
> ```
> array.sort((first, second) => first - second);
> ```
>
> Numbers could be sorted with:
>
> ```
> array.sort(Math.sub);
> ```
>
> `Math.mul` and `Math.div`: I don't have a compelling use case in mind,
> but I'd just throw these in for good measure / symmetry.
>
> Ates
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190507/aac64bdc/attachment.html>


More information about the es-discuss mailing list