[#120855] [Ruby master Bug#21104] Net::HTTP connections failing in Ruby >= 3.4.0 on macOS with Happy Eyeballs enabled — "mjt58 (Mike Thompson) via ruby-core" <ruby-core@...>

Issue #21104 has been reported by mjt58 (Mike Thompson).

14 messages 2025/02/01

[#120873] [Ruby master Bug#21111] RbConfig::CONFIG['CXX'] quietly set to "false" when Ruby cannot build C++ programs — "stanhu (Stan Hu) via ruby-core" <ruby-core@...>

Issue #21111 has been reported by stanhu (Stan Hu).

10 messages 2025/02/03

[#120884] [Ruby master Bug#21115] Etc.getgrgid is not Ractor-safe but is marked as such — "Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>

Issue #21115 has been reported by Eregon (Benoit Daloze).

7 messages 2025/02/05

[#120897] [Ruby master Bug#21119] Programs containing `Dir.glob` with a thread executing a CPU-heavy task run very slowly. — "genya0407 (Yusuke Sangenya) via ruby-core" <ruby-core@...>

Issue #21119 has been reported by genya0407 (Yusuke Sangenya).

6 messages 2025/02/06

[#121054] [Ruby master Bug#21139] Prism and parse.y parses `it = it` differently — "tompng (tomoya ishida) via ruby-core" <ruby-core@...>

Issue #21139 has been reported by tompng (tomoya ishida).

19 messages 2025/02/14

[#121060] [Ruby master Feature#21140] Add a method to get the address of certain JIT related functions — "tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@...>

Issue #21140 has been reported by tenderlovemaking (Aaron Patterson).

23 messages 2025/02/14

[#121077] [Ruby master Misc#21143] Speficy order of execution const_added vs inherited — "fxn (Xavier Noria) via ruby-core" <ruby-core@...>

Issue #21143 has been reported by fxn (Xavier Noria).

15 messages 2025/02/17

[#121142] [Ruby master Misc#21154] Document or change Module#autoload? — "fxn (Xavier Noria) via ruby-core" <ruby-core@...>

Issue #21154 has been reported by fxn (Xavier Noria).

32 messages 2025/02/23

[#121172] [Ruby master Feature#21157] Comparison operator <> — lpogic via ruby-core <ruby-core@...>

SXNzdWUgIzIxMTU3IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGxwb2dpYyAoxYF1a2FzeiBQb21pZXTF

11 messages 2025/02/26

[ruby-core:121053] [Ruby master Feature#21135] Feature request: Enumerable.compare_count

From: "kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>
Date: 2025-02-14 17:19:30 UTC
List: ruby-core #121053
Issue #21135 has been updated by kddnewton (Kevin Newton).


We already have lazy enumerators, so I think your request can be simplified a bit by taking advantage of that and defining Enumerator::Lazy#length to return an object that knows how to compare itself to other stuff. Something like:

```ruby
class Enumerator
  class Lazy
    class Length
      def initialize(enum)
        @enum = enum
      end
    
      def force = @enum.to_a.length
      def <=>(value) = force <=> value
    
      def <(value) = value >= 0 && @enum.take(value).to_a.length < value
      def <=(value) = value >= 0 && @enum.take(value + 1).to_a.length <= value
      def >(value) = value <= 0 || @enum.take(value + 1).to_a.length > value
      def >=(value) = value <= 0 || @enum.take(value).to_a.length == value
      def ==(value) = value >= 0 && @enum.take(value + 1).to_a.length == value
      def !=(value) = value < 0 || @enum.take(value + 1).to_a.length != value
    end

    def length = Length.new(self)
  end
end
```

In your example, instead of `d.compare_count(op, x)` this would instead be `d.lazy.length.public_send(op, x)`, and instead of `d.compare_count(op, x){|p| Prime.prime?(p)}` it would instead be `d.lazy.select { |p| Prime.prime?(p) }.length.public_send(op, x)`.

I don't know if this is applicable enough to other projects that it would merit being in core, but I _do_ think this would be simpler than the requested method.

----------------------------------------
Feature #21135: Feature request: Enumerable.compare_count
https://bugs.ruby-lang.org/issues/21135#change-111968

* Author: Student (Nathan Zook)
* Status: Open
----------------------------------------
Enumerables at times can be quite expensive to complete expand.  If all is desired is to compare the count, we can terminate the enumeration once the result is known.

The functionality that I envision, if implemented in ruby, might look like this:

```ruby
module Enumerable
  def compare_count(operation, standard, &blk)
    case operation
    when :<
      compare_count_lt(standard, &blk)
    when :>=
      !compare_count_lt(standard, &blk)
    when :>
      compare_count_spaceship(standard, &blk) == 1
    when :<=
      compare_count_spaceship(standard, &blk) != 1
    when :==
      compare_count_spaceship(standard, &blk) == 0
    when :!=
      compare_count_spaceship(standard, &blk) != 0
    end
  end

  def compare_count_lt(standard, &blk)
    truncate_count(standard - 1, &blk) < standard
  end

  def compare_count_spaceship(standard, &blk)
    truncate_count(standard, &blk) <=> standard
  end

  def truncate_count(limit, &blk)
    return 0 if limit < 0
    found = 0
    each do |ele|
      found += 1 unless blk && !yield(ele)
      break if found > limit
    end
    found
  end
end

class Demo
  include Enumerable

  attr_reader :capacity
  attr_reader :cnt

  def initialize(capacity)
    @capacity = capacity
  end

  def each
    @cnt = 0
    while cnt < capacity
      @cnt += 1
      yield cnt
    end
  end
end

%i{< <= >= > == !=}.each do |op|
  d = Demo.new(3)
  (-1..5).each do |x|
    puts [op, x, d.compare_count(op, x), d].inspect
  end
end


require 'prime'

%i{< <= >= > == !=}.each do |op|
  d = Demo.new(6)
  (-1..5).each do |x|
    puts [op, x, d.compare_count(op, x){|p| Prime.prime?(p)} , d].inspect
  end
end

```

```
[:<, -1, false, #<Demo:0x034d567c @capacity=3>]
[:<, 0, false, #<Demo:0x034d567c @capacity=3>]
[:<, 1, false, #<Demo:0x034d567c @capacity=3, @cnt=1>]
[:<, 2, false, #<Demo:0x034d567c @capacity=3, @cnt=2>]
[:<, 3, false, #<Demo:0x034d567c @capacity=3, @cnt=3>]
[:<, 4, true, #<Demo:0x034d567c @capacity=3, @cnt=3>]
[:<, 5, true, #<Demo:0x034d567c @capacity=3, @cnt=3>]
[:<=, -1, false, #<Demo:0x034d512c @capacity=3>]
[:<=, 0, false, #<Demo:0x034d512c @capacity=3, @cnt=1>]
[:<=, 1, false, #<Demo:0x034d512c @capacity=3, @cnt=2>]
[:<=, 2, false, #<Demo:0x034d512c @capacity=3, @cnt=3>]
[:<=, 3, true, #<Demo:0x034d512c @capacity=3, @cnt=3>]
[:<=, 4, true, #<Demo:0x034d512c @capacity=3, @cnt=3>]
[:<=, 5, true, #<Demo:0x034d512c @capacity=3, @cnt=3>]
[:>=, -1, true, #<Demo:0x034d4d44 @capacity=3>]
[:>=, 0, true, #<Demo:0x034d4d44 @capacity=3>]
[:>=, 1, true, #<Demo:0x034d4d44 @capacity=3, @cnt=1>]
[:>=, 2, true, #<Demo:0x034d4d44 @capacity=3, @cnt=2>]
[:>=, 3, true, #<Demo:0x034d4d44 @capacity=3, @cnt=3>]
[:>=, 4, false, #<Demo:0x034d4d44 @capacity=3, @cnt=3>]
[:>=, 5, false, #<Demo:0x034d4d44 @capacity=3, @cnt=3>]
[:>, -1, true, #<Demo:0x034d4998 @capacity=3>]
[:>, 0, true, #<Demo:0x034d4998 @capacity=3, @cnt=1>]
[:>, 1, true, #<Demo:0x034d4998 @capacity=3, @cnt=2>]
[:>, 2, true, #<Demo:0x034d4998 @capacity=3, @cnt=3>]
[:>, 3, false, #<Demo:0x034d4998 @capacity=3, @cnt=3>]
[:>, 4, false, #<Demo:0x034d4998 @capacity=3, @cnt=3>]
[:>, 5, false, #<Demo:0x034d4998 @capacity=3, @cnt=3>]
[:==, -1, false, #<Demo:0x034d4600 @capacity=3>]
[:==, 0, false, #<Demo:0x034d4600 @capacity=3, @cnt=1>]
[:==, 1, false, #<Demo:0x034d4600 @capacity=3, @cnt=2>]
[:==, 2, false, #<Demo:0x034d4600 @capacity=3, @cnt=3>]
[:==, 3, true, #<Demo:0x034d4600 @capacity=3, @cnt=3>]
[:==, 4, false, #<Demo:0x034d4600 @capacity=3, @cnt=3>]
[:==, 5, false, #<Demo:0x034d4600 @capacity=3, @cnt=3>]
[:!=, -1, true, #<Demo:0x034d4268 @capacity=3>]
[:!=, 0, true, #<Demo:0x034d4268 @capacity=3, @cnt=1>]
[:!=, 1, true, #<Demo:0x034d4268 @capacity=3, @cnt=2>]
[:!=, 2, true, #<Demo:0x034d4268 @capacity=3, @cnt=3>]
[:!=, 3, false, #<Demo:0x034d4268 @capacity=3, @cnt=3>]
[:!=, 4, true, #<Demo:0x034d4268 @capacity=3, @cnt=3>]
[:!=, 5, true, #<Demo:0x034d4268 @capacity=3, @cnt=3>]
[:<, -1, false, #<Demo:0x00007f64147c37e0 @capacity=6>]
[:<, 0, false, #<Demo:0x00007f64147c37e0 @capacity=6>]
[:<, 1, false, #<Demo:0x00007f64147c37e0 @capacity=6, @cnt=2>]
[:<, 2, false, #<Demo:0x00007f64147c37e0 @capacity=6, @cnt=3>]
[:<, 3, false, #<Demo:0x00007f64147c37e0 @capacity=6, @cnt=5>]
[:<, 4, true, #<Demo:0x00007f64147c37e0 @capacity=6, @cnt=6>]
[:<, 5, true, #<Demo:0x00007f64147c37e0 @capacity=6, @cnt=6>]
[:<=, -1, false, #<Demo:0x00007f64147c21d8 @capacity=6>]
[:<=, 0, false, #<Demo:0x00007f64147c21d8 @capacity=6, @cnt=2>]
[:<=, 1, false, #<Demo:0x00007f64147c21d8 @capacity=6, @cnt=3>]
[:<=, 2, false, #<Demo:0x00007f64147c21d8 @capacity=6, @cnt=5>]
[:<=, 3, true, #<Demo:0x00007f64147c21d8 @capacity=6, @cnt=6>]
[:<=, 4, true, #<Demo:0x00007f64147c21d8 @capacity=6, @cnt=6>]
[:<=, 5, true, #<Demo:0x00007f64147c21d8 @capacity=6, @cnt=6>]
[:>=, -1, true, #<Demo:0x00007f64147c0860 @capacity=6>]
[:>=, 0, true, #<Demo:0x00007f64147c0860 @capacity=6>]
[:>=, 1, true, #<Demo:0x00007f64147c0860 @capacity=6, @cnt=2>]
[:>=, 2, true, #<Demo:0x00007f64147c0860 @capacity=6, @cnt=3>]
[:>=, 3, true, #<Demo:0x00007f64147c0860 @capacity=6, @cnt=5>]
[:>=, 4, false, #<Demo:0x00007f64147c0860 @capacity=6, @cnt=6>]
[:>=, 5, false, #<Demo:0x00007f64147c0860 @capacity=6, @cnt=6>]
[:>, -1, true, #<Demo:0x00007f64147df260 @capacity=6>]
[:>, 0, true, #<Demo:0x00007f64147df260 @capacity=6, @cnt=2>]
[:>, 1, true, #<Demo:0x00007f64147df260 @capacity=6, @cnt=3>]
[:>, 2, true, #<Demo:0x00007f64147df260 @capacity=6, @cnt=5>]
[:>, 3, false, #<Demo:0x00007f64147df260 @capacity=6, @cnt=6>]
[:>, 4, false, #<Demo:0x00007f64147df260 @capacity=6, @cnt=6>]
[:>, 5, false, #<Demo:0x00007f64147df260 @capacity=6, @cnt=6>]
[:==, -1, false, #<Demo:0x00007f64147dd898 @capacity=6>]
[:==, 0, false, #<Demo:0x00007f64147dd898 @capacity=6, @cnt=2>]
[:==, 1, false, #<Demo:0x00007f64147dd898 @capacity=6, @cnt=3>]
[:==, 2, false, #<Demo:0x00007f64147dd898 @capacity=6, @cnt=5>]
[:==, 3, true, #<Demo:0x00007f64147dd898 @capacity=6, @cnt=6>]
[:==, 4, false, #<Demo:0x00007f64147dd898 @capacity=6, @cnt=6>]
[:==, 5, false, #<Demo:0x00007f64147dd898 @capacity=6, @cnt=6>]
[:!=, -1, true, #<Demo:0x00007f64147dbf20 @capacity=6>]
[:!=, 0, true, #<Demo:0x00007f64147dbf20 @capacity=6, @cnt=2>]
[:!=, 1, true, #<Demo:0x00007f64147dbf20 @capacity=6, @cnt=3>]
[:!=, 2, true, #<Demo:0x00007f64147dbf20 @capacity=6, @cnt=5>]
[:!=, 3, false, #<Demo:0x00007f64147dbf20 @capacity=6, @cnt=6>]
[:!=, 4, true, #<Demo:0x00007f64147dbf20 @capacity=6, @cnt=6>]
[:!=, 5, true, #<Demo:0x00007f64147dbf20 @capacity=6, @cnt=6>]

```





-- 
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/lists/ruby-core.ml.ruby-lang.org/


In This Thread