[ruby-core:77956] Re: [Ruby trunk Feature#12902] How about Enumerable#sum uses initial value rather than 0 as default?

From: Martin J. Dürst <duerst@...>
Date: 2016-11-05 01:43:44 UTC
List: ruby-core #77956
On 2016/11/05 04:28, aaron.lasseigne@gmail.com wrote:
> Issue #12902 has been updated by Aaron Lasseigne.

> In https://bugs.ruby-lang.org/issues/12217#note-3, Akira Tanaka, mentions that the default argument to sum is 0. This creates problems with non-numeric summations (e.g. strings). I would like to suggest using the first enumerable value. This would make the method more flexible. It also makes it behave more like reduce. I think using the initial value in the enumerable is less surprising than using 0.

What would/should the behavior be for an empty array?

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next