Repository navigation
Enumerable: advance MRI 4.0.6 conformance (aliases, sizes, min/max/reduce/find, cycle/zip/sum/lazy) - #532
Merged
Conversation
…mily - collect/filter/detect/find_all/collect_concat/inject are now genuine aliases (alias, not wrapper defs), so Enumerable.instance_method(:collect) == instance_method(:map) etc., matching MRI 4.0.6. - flat_map now uses Array.try_convert on each yielded value: concatenates a #to_ary result, appends when it returns nil, raises TypeError otherwise. - enum_for size functions match MRI: origin-size methods (map, select, reject, flat_map, min_by, max_by, sort_by, minmax_by, group_by, partition, each_with_index, each_with_object, filter_map) return the receiver size when it responds to #size and nil otherwise; unknown-size methods (find, find_index, take_while, drop_while) return nil. - Regenerated prelude_frozen_gen.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… ifnone - min/max/minmax now compare with the block when given, else with <=>, and raise ArgumentError on a nil comparison (incomparable elements or a block returning nil), matching MRI. Multi-value #each yields are compared as gathered arrays; min(n)/max(n) sort with the block. - reduce/inject accept a String (or #to_str) operator, decide a lone argument as init vs operator by block presence, raise TypeError for a non-symbol/ non-string operator, and ArgumentError for zero args without a block or more than two args. - find/detect accept an ifnone argument, calling it when nothing matches (raising NoMethodError if it does not respond to #call) and threading it through the no-block enumerator. - Regenerated prelude_frozen_gen.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…y, arity - entries is an alias of to_a and member? an alias of include? (genuine aliases, matching MRI's instance_method identity). - to_a, to_h, each_with_index, and each_entry forward their arguments to #each, as MRI does. - to_h coerces each pair with Array.try_convert (#to_ary), matching MRI's element-type and array-length errors. - to_set accepts the set class as an optional first argument (plus extra args), instantiating it with the elements. - tally converts a non-Hash argument with #to_hash before tallying into it. - map, find_index, and take_while forward the raw #each yield to the block so block arity governs multi-value yields (a single-parameter block takes the first value; a splat gathers), matching MRI. - Regenerated prelude_frozen_gen.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- zip converts a non-Array argument with #to_ary, else #to_enum(:each), and raises TypeError (must respond to :each) when it responds to neither, matching MRI. - sum switches to Kahan-Babuska-Neumaier compensated summation once a Float is involved, so a long run of floats sums without drift. - cycle coerces n through #to_int (TypeError on failure), does nothing without touching #each for a non-positive n, and drives #each directly on the first pass (buffering for later cycles) so a breaking block yields only as needed and #each is called at most once. - Regenerated prelude_frozen_gen.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Any class that mixes in Enumerable and defines #each now answers #lazy, returning an Enumerator::Lazy driven through #each (lazySource's default path already materialises an arbitrary receiver via #each). Previously #lazy was defined only on Array, Range, Hash and Enumerator. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… branches New vm_test cases in enumerable_residuals_test.go covering the genuine aliases (identical UnboundMethods), origin- vs unknown-size enumerators, min/max/minmax comparator + ArgumentError, reduce/inject operator forms, find ifnone, argument forwarding, to_h #to_ary coercion, flat_map, lazy on a bare Enumerable, and the reduce/find/cycle/zip error branches. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Aug 31, 2026
Locks in the gains from #530 (Encoding compatibility: Converter.new, concat negotiation, multibyte codepoints, ascii_only?), #531 (language def/method/super/keyword-argument), #532 (Enumerable residuals) and #533 (Array/Hash value equality dispatching #==/#eql?/#hash). Measured 17654 passing on the pinned corpus, up from 17470. 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.
Advances
core/enumerable/*_spec.rbconformance toward MRI Ruby 4.0.6. Enumerable total across the corpus went from ~pass=485/fail=48/error=25 to pass=515 / fail=8 / error=4, with these full-spec files now passing completely: collect, detect, filter, find_all, reduce, collect_concat, flat_map, find, find_index, take_while, drop_while, each_with_index, each_with_object, each_entry, entries, member, to_a, to_h, to_set, tally, min, max, minmax, min_by, max_by, minmax_by, group_by, partition, filter_map, select, reject, map (all non-Hash/VM parts), sum, cycle, zip, lazy, reverse_each.Changes (all in
internal/vm/prelude.rbEnumerable, plus one line ininternal/vm/lazy.go)collect/filter/detect/find_all/collect_concat/inject/entries/member?are now realaliases of their targets, soEnumerable.instance_method(:collect) == instance_method(:map)etc., matching MRI.#sizeandnilotherwise; unknown-size methods (find, find_index, take_while, drop_while) reportnil.<=>; raiseArgumentErroron a nil comparison; gather multi-value yields as arrays.#to_stroperator, decide a lone argument as init vs operator by block presence, and raise the rightTypeError/ArgumentError.ifnoneargument.#eachforto_a,to_h,each_with_index,each_entry.Array.try_convert(#to_ary); to_set accepts the set class; tally converts a non-Hash argument via#to_hash.Array.try_convertper element; zip converts via#to_ary/#to_enum(:each)with aTypeErrorfallback; sum uses Kahan-Babuska-Neumaier compensation for floats; cycle coercesnvia#to_int, no-ops for non-positivenwithout touching#each, and iterates lazily on the first pass.#each-defining class gets it.The frozen prelude (
prelude_frozen_gen.go) was regenerated viago generate.Known residuals (out of scope for the Enumerable builtins)
$~preservation needs frame-local$~and a working$~=(VM-level).mapcases depend onHash#eachyielding two args and onsuper/block-arity mechanics (VM/Hash).sort_by's one failure is a spec_helper mock limitation (and_yieldchain yields only the last value).uniq/sort/injectmutation cases route to native Array methods.Verification
go test ./internal/vm/green;go test ./...green;GOOS=js GOARCH=wasmbuild OK;gofmt -lclean on changed Go files.-coverpkg ./internal/...) = 100.0%.🤖 Generated with Claude Code