From: "matz (Yukihiro Matsumoto) via ruby-core" Date: 2023-10-12T07:59:22+00:00 Subject: [ruby-core:115011] [Ruby master Feature#18515] Add Range#reverse_each implementation Issue #18515 has been updated by matz (Yukihiro Matsumoto). I accept this as a performance improvement. Matz. ---------------------------------------- Feature #18515: Add Range#reverse_each implementation https://bugs.ruby-lang.org/issues/18515#change-104881 * Author: kyanagi (Kouhei Yanagita) * Status: Open * Priority: Normal ---------------------------------------- PR is ~~https://github.com/ruby/ruby/pull/5489~~ https://github.com/ruby/ruby/pull/8525 Current `Range#reverse_each` uses `Enumerable#reverse_each` which is implemented with `#to_a`. So we are virtually not able to use `reverse_each` for a very large or beginless range, even if few elements are iterated on actually. ``` (1..2**100).reverse_each { |x| p x; break if x.odd? } (..5).reverse_each { |x| p x; break if x == 0 } (1..2**32).reverse_each.lazy.select { |x| Prime.prime?(x) }.take(3).to_a ``` This patch, implements `Range#reverse_each` for Integer elements, enables these examples. I think `#reverse_each` for an endless range should raise an exception. This is a different issue, so I'll create another ticket later. -> posted: https://bugs.ruby-lang.org/issues/18551 -- 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/