Skip to content

Lazy enumerable select eagerly evaluates next item #4212

@headius

Description

@headius

Discovered by @twalpole in SeleniumHQ/selenium#2880. It appears our lazy enumerable logic is trying to evaluate the next item eagerly, or something...

class A
  include Enumerable

  def initialize()
    @result_enum = ["Text", "Text", "Text"].lazy.select do |t|
      puts "evaluating lazy select"
      true
    end
  end

  def each(&block)
    loop do
      block.call(@result_enum.next)
    end
  end
end

A.new().first

Running this on MRI prints "evaluating lazy select" once, while JRuby prints it twice.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions