[#115244] [Ruby master Feature#19987] add sample method to Range — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19987 has been reported by horv77@protonmail.com (Andras Horvath).
6 messages
2023/11/05
[#115247] [Ruby master Feature#19988] AI for inner code behavior analysis at runtime — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19988 has been reported by horv77@protonmail.com (Andras Horvath).
3 messages
2023/11/05
[#115404] Ruby 3.2.2 - rbconfig.rb's MAKEFILE_CONFIG — Jay Mav via ruby-core <ruby-core@...>
Hello Ruby Dev Team,
4 messages
2023/11/17
[ruby-core:115298] [Ruby master Feature#19324] Enumerator.product => Enumerable#product
From:
"mame (Yusuke Endoh) via ruby-core" <ruby-core@...>
Date:
2023-11-08 00:47:13 UTC
List:
ruby-core #115298
Issue #19324 has been updated by mame (Yusuke Endoh). Discussed at the dev meeting. @knu will respond, but I'll give you just an overview of the discussion. * We do not remove `Enumerator.product`. * We may add `Enumerable#product` that returns an Array (not an Enumerator) * because returning a non-Array is incompatible with existing `Array#product`. * also because Enumerable methods usually returns an Array. * If so, we will introduce `Enumerable::Lazy#product` too. * You will be able to use `.lazy` to get an Enumerator of product. ``` [1, 2].product([3, 4]) #=> [[1, 3], [1, 4], [2, 3], [2, 4]] [1, 2].to_enum.product([3, 4]) #=> [[1, 3], [1, 4], [2, 3], [2, 4]] [1, 2].lazy.product([3, 4]) #=> #<Enumerator::Lazy ... > [1, 2].lazy.product([3, 4]).eager #=> #<Enumerator ... > [1, 2].lazy.product([3, 4]).force #=> [[1, 3], [1, 4], [2, 3], [2, 4]] ``` ---------------------------------------- Feature #19324: Enumerator.product => Enumerable#product https://bugs.ruby-lang.org/issues/19324#change-105216 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal ---------------------------------------- I know it might be too late after introducing a feature and releasing a version, but I find `Enumerator.product` quite confusing, and can't find any justification in #18685. **Problem 1: It is `Array#product` but `Enumerator.product`** ```ruby [1, 2].product([4, 5]) # => [[1, 4], [1, 5], [2, 4], [2, 5]] # Usually, when we add methods to Enumerable/Enumerator which # already array had before, it is symmetric, say... [1, nil, 2, 3].compact #=> [1, 2, 3] [1, nil, 2, 3].lazy.compact.first(2) #=> [1, 2] # But not in this case: [1, 2].lazy.product([4, 5]).first(2) # undefined method `product' for #<Enumerator::Lazy: [1, 2]> (NoMethodError) # Because you "just" need to change it to: Enumerator.product([1, 2].lazy, [4, 5]).first(2) # => [[1, 4], [1, 5]] ``` No other method was "promoted" from Array this way And in general, I believe core methods tend to belong to the first object in the expression and not be free module methods, Elixir style. **Problem 2: It is one letter different from `Enumerator.produce`** I understand I might be biased here (as a person who proposed `produce`), and that method is not as popular (yet?) as I hoped, but still, two methods that do completely different things and differ by one letter, both being somewhat vague verbs (so it is easy to confuse them unless you did a lot of math and "product" is firmly set for set product in your head). I believe that EITHER of two problems would be concerning enough, but the combination of them seems to be a strong enough argument to make the change?.. (Maybe with graceful deprecation of module method in one next version, but, considering the Ruby 3.2 is just released, maybe vice versa, fix the problem in the next minor release?..) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/