Project

General

Profile

Actions

Feature #19294

open

Enumerator.product works incorrectly with consuming enumerators

Added by zverok (Victor Shepelev) over 1 year ago. Updated 12 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:111566]

Description

s = StringIO.new('abc')
Enumerator.product([1, 2, 3], s.each_char).to_a
# Expected: => [[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], [2, "c"], [3, "a"], [3, "b"], [3, "c"]]
# Actual: => [[1, "a"], [1, "b"], [1, "c"]]

The implementation consumes the non-first enumerator to produce the first combination.

Somewhat related to the dilemma of consuming and non-consuming enumerators (#19061).

PS: I noticed I don't understand why it is Enumerator.product and not Enumerable#product, but probably it is too late to raise the questions :(

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0