Repository navigation
Add Enumerator.product / Enumerator::Product - #456
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enumerator.productwas undefined andEnumerator::Productwas an uninitializedconstant.
Enumerator.productnow returns anEnumerator::Productover theCartesian product of its enumerable arguments.
Each source is consumed through
#each_entry, lazily and afresh at every outerstep: an infinite source yields an infinite product (so
#takeworks), and aone-shot source is drained only once (matching MRI, whose second pass over such a
source yields nothing). A multi-value
#each_entryyield keeps its first valueand a bare yield contributes
nil.#sizeis the product of the sources' sizes—
Float::INFINITYwhen any is infinite,nilwhen any is unknown,1for nosources. With a block it iterates and returns
nil; keyword arguments arerejected; and an argument that does not respond to
#each_entryraisesNoMethodError(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 anisProductflag thatclassOfmaps tothe new
Enumerator::Productclass.Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep;
core/enumerator/product_spec0 → 11 andcore/enumerator/product/initialize_spec0 → 3. (The oneproduct_specexample still failing exercises an endless Range source, blocked by a separate,
pre-existing
Range#eachlimitation, not byEnumerator.product.)🤖 Generated with Claude Code