Skip to content

Add Enumerator.product / Enumerator::Product - #456

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster26
Aug 25, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster26

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Enumerator.product was undefined and Enumerator::Product was an uninitialized
constant. Enumerator.product now returns an Enumerator::Product over the
Cartesian product of its enumerable arguments.

Each source is consumed through #each_entry, lazily and afresh at every outer
step
: an infinite source yields an infinite product (so #take works), and a
one-shot source is drained only once (matching MRI, whose second pass over such a
source yields nothing). A multi-value #each_entry yield keeps its first value
and a bare yield contributes nil. #size is the product of the sources' sizes
— Float::INFINITY when any is infinite, nil when any is unknown, 1 for no
sources. With a block it iterates and returns nil; keyword arguments are
rejected; and an argument that does not respond to #each_entry raises
NoMethodError (lazily, on iteration).

The generator is a native Go block, so no new Ruby runs at boot (Enumerator is
registered after the prelude, so the class and singleton method are defined in
registerEnumerator). Instances carry an isProduct flag that classOf maps to
the new Enumerator::Product class.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep; core/enumerator/product_spec 0 → 11 and
core/enumerator/product/initialize_spec 0 → 3. (The one product_spec
example still failing exercises an endless Range source, blocked by a separate,
pre-existing Range#each limitation, not by Enumerator.product.)

🤖 Generated with Claude Code

Enumerator.product was undefined and Enumerator::Product was an uninitialized
constant. Enumerator.product now returns an Enumerator::Product over the
Cartesian product of its enumerable arguments.

Each source is consumed through #each_entry, lazily and afresh at every outer
step: an infinite source yields an infinite product (so #take works), and a
one-shot source is drained only once (matching MRI, whose second pass over such a
source yields nothing). A multi-value #each_entry yield keeps its first value and
a bare yield contributes nil. #size is the product of the sources' sizes —
Float::INFINITY when any is infinite, nil when any is unknown, 1 for no sources.
With a block it iterates the product and returns nil; keyword arguments are
rejected; and an argument that does not respond to #each_entry raises
NoMethodError (lazily, on iteration).

The generator is a native Go block, so no new Ruby runs at boot (Enumerator is
registered after the prelude, so the class and singleton method are defined in
registerEnumerator). Instances carry an isProduct flag that classOf maps to the
new Enumerator::Product class.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/enumerator/product_spec 0 -> 11 and
core/enumerator/product/initialize_spec 0 -> 3. (The one product_spec example
still failing exercises an *endless Range* source, blocked by a separate,
pre-existing Range#each limitation, not by Enumerator.product.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit e22ca76 into main Aug 25, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster26 branch August 25, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant