From: blackmoore.joan@... Date: 2018-01-31T20:10:01+00:00 Subject: [ruby-core:85317] [Ruby trunk Feature#14399] Add Enumerable#product Issue #14399 has been updated by joanbm (Joan Blackmoore). I'd also vote YES for this feature request, move `#product` into `Enumerable`. It is especially missing when working with (lazy) infinite sequences and problems leading to cartesian product of elements. Now it has to by implemented by nesting blocks of `Enumerable#flat_map`, which is cumbersome and inelegant when, ironically, there is method already available but for Array (sub)class(es) only. p.s. Please stay on topic, discussion about chosen method name is pointless because it is already there. Backward compatibility should be kept as possible and its name is also justified although opinions may differ. ---------------------------------------- Feature #14399: Add Enumerable#product https://bugs.ruby-lang.org/issues/14399#change-70102 * Author: jzakiya (Jabari Zakiya) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- For similar reasons for creating `Enumerable#sum` a companion method `Enumerable#product` is also very useful. Taking the product of numbers in arrays is a common operation in many numerical algorithms, especially in number theory and cryptography, and its optimization in Ruby will make it more conducive to math heavy algorithms and tasks. This ``` > [2,3,5,7].reduce(:*) => 210 ``` can be optimized to this ``` > [2,3,5,7].product => 210 ``` It should also allow an initial value ``` > [2,3,5,7].product(2) => 420 > [2,3,5,7].product(0.5) => 105 ``` Crystal already has this `method`. -- https://bugs.ruby-lang.org/ Unsubscribe: