Skip to content

Enumerator's Yielder does not pass through one-elt array properly #4108

@headius

Description

@headius

This is the continuation of #3814.

See the discussion there for the long form.

Short form, the following script should produce the given result. Two fail as shown by specs in #3814, and one works currently but may be the incorrect fix (#2458).

class Enumerator::Yielder
    def yield(*args)
      @proc.call(*args)
    end
end

module Enumerable
  def first
    val = nil
    catch(:foo) do
      each do |x|
        val = x
        throw :foo
      end
    end
    val
  end
end

p Enumerator.new {|y| y.yield([1])}.to_a
p Enumerator.new {|y| y << [1]}.to_a
p Enumerator.new {|y| y.yield([1])}.map {|e| e}.to_a
p Enumerator.new {|y| y.yield([1])}.lazy.map {|e| e}.to_a
p Enumerator.new {|y| y.yield [1]}.first
$ jruby blah.rb
[[1]]
[[1]]
[[1]]
[[1]]
[1]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions