Proposal: Array.prototype.accumulate and Array.prototype.accumulateRight

Alexander Jones alex at weej.com
Thu Oct 27 22:05:41 UTC 2016


Can we please start talking about Iterators already? The Python community
are laughing at us! Widening the Array prototype is like putting lipstick
on a pig...

On Thursday, 27 October 2016, Bergi <a.d.bergi at web.de> wrote:

> Mark M. Young wrote:
>
>> I am proposing a replacement for Array.prototype.reduce and
>> Array.prototype.reduceRight.
>>
>
> Nice. Allowing to pass an argument for the `this` value was missing when
> folding an array, and your suggestion `accumulate` is a fitting method name.
>
> However, I fear the use cases are too unimportant to need a fix.
> The `this` keyword is becoming less and less used for anything but class
> methods. And for those, arrow functions solve the problem needing to invoke
> functions on the expected receiver.
> For passing in data to a reusable reducer function, closures are much
> simpler than setting the `this` value for the callback.
>
> https://github.com/MarkMYoung/ArrayAccumulate <
> https://github.com/MarkMYoung/ArrayAccumulate> says
>
>> `reduce` is not reusable code because there is no way to know what the
>> second parameter was once beyond the first iteration.
>>
>
> That makes no sense. The whole point of the initial value parameter is
> that it only goes into the first call (if any), or is the return value in
> case the array is empty.
>
> the second parameter is always available as `this`.
>>
>
> It really should not be. If you want to pass a value for `this`, it needs
> a third parameter.
>
> kind regards,
>  Bergi
> _______________________________________________
> 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/20161027/5b5b6334/attachment.html>


More information about the es-discuss mailing list