Bug #18971
Updated by Voileexperiments (Library Voile) over 2 years ago
These results with lazy enumerators are as expected: ``` ruby (2..10).take(0).to_a # => [] (2..10).take(0).map(:&itself).to_a # => [] (2..10).lazy.take(0).to_a # => [] ``` However, once another operation is added after `take(0)`, if first element will pass through directly it will leak through: ``` ruby (2..10).lazy.take(0).map(&:itself).to_a # => [2] (2..10).lazy.take(0).select(&:even?).to_a # => [2] (2..10).lazy.take(0).select(&:odd?).to_a # => [] (2..10).lazy.take(0).reject(&:even?).to_a # => [] (2..10).lazy.take(0).reject(&:odd?).to_a # => [2] (2..10).lazy.take(0).take(1).to_a # => [2] (2..10).lazy.take(0).take(0).take(1).to_a # => [2] (2..10).lazy.take(0).drop(0).to_a # => [2] (2..10).lazy.take(0).find_all {|_| true}.to_a # => [2] (2..10).lazy.take(0).zip((12..20)).to_a # => [[2, 12]] (2..10).lazy.take(0).uniq.to_a # => [2] (2..10).lazy.take(0).sort.to_a # => [] (2..2).lazy.take(0).sort.to_a # => [] ``` Non lazy versions all return `[]` as expected. In 3.1.0 All of them behave as expected as well: ``` ruby (2..10).lazy.take(0).map(&:itself).to_a # => [] (2..10).lazy.take(0).select(&:even?).to_a # => [] (2..10).lazy.take(0).select(&:odd?).to_a # => [] (2..10).lazy.take(0).reject(&:even?).to_a # => [] (2..10).lazy.take(0).reject(&:odd?).to_a # => [] (2..10).lazy.take(0).take(1).to_a # => [] (2..10).lazy.take(0).take(0).take(1).to_a # => [] (2..10).lazy.take(0).drop(0).to_a # => [] (2..10).lazy.take(0).find_all {|_| true}.to_a # => [] (2..10).lazy.take(0).zip((12..20)).to_a # => [] (2..10).lazy.take(0).uniq.to_a # => [] (2..10).lazy.take(0).sort.to_a # => [] (2..2).lazy.take(0).sort.to_a # => [] ```