Project

General

Profile

Actions

Feature #12902

closed

How about Enumerable#sum uses initial value rather than 0 as default?

Added by AaronLasseigne (Aaron Lasseigne) about 8 years ago. Updated almost 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:77929]

Description

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). 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0