refactor(dummies): share the collection count facade across generators#285
Merged
Conversation
AnyDictionary re-implemented the entire count facade — NonEmpty, Empty, WithCount, WithMinCount, WithMaxCount, WithCountBetween plus the RequireNonNegative/V helpers — verbatim from AnyCollection, so any fix or message change to the count algebra had to be mirrored by hand and could silently drift between the two surfaces. Extract that logic once into an internal CountConstraints helper over CollectionState: each generator now delegates its count methods to the helper and wraps the returned state in its own immutable type. The AnyCollection builders (list, array, sequence, set) and AnyDictionary now share a single definition. Behaviour is unchanged: public signatures, exception types and parameter names, and the constraint labels that surface in conflict messages are all preserved, and the labels stay out of the label-agnostic CollectionState. Refs: #225 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018RduXUaM3V6tk6MuKxzVzJ
This was referenced Jul 22, 2026
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.
Summary
AnyDictionaryre-implemented the entire collection count facade —NonEmpty/Empty/WithCount/WithMinCount/WithMaxCount/WithCountBetweenplus theRequireNonNegative/Vhelpers — verbatim fromAnyCollection, so any fix or message change to the count algebra had to be mirrored by hand and could silently drift between the two surfaces. This extracts that logic once into an internal helper both surfaces delegate to. No behaviour change.This is change 1 of the two independent changes described in #225 (the shared count facade); the containment surface (
ContainingKey) is left for a follow-up.Type of change
Changes
Dummies/CountConstraints.cs: an internal static helper defining the six count operations once overCollectionState<T>, carrying the argument validation and the constraint labels that surface inConflictingAnyConstraintException.AnyCollection<TItem, TResult, TSelf>(list, array, sequence, set) now delegates its count methods toCountConstraintsand drops its privateRequireNonNegative/Vhelpers.AnyDictionary<TKey, TValue>delegates its key-count methods to the same helper, removing the ~60-line verbatim copy.PublicAPI.*.txtbaselines are untouched). Labels stay produced in the facade rather than in the label-agnosticCollectionState.Testing
dotnet build FirstClassErrors.sln— Build succeeded, 0 Warning(s), 0 Error(s) (both thenetstandard2.0andnet8.0legs of Dummies compiled).dotnet test FirstClassErrors.sln— full suite not run locally; randotnet test Dummies.UnitTestsinstead: 448 passed, 0 failed, 0 skipped.FirstClassErrors.Analyzers.UnitTests) — not run; no analyzer change in this PR.Documentation
doc/updateddoc/handwritten/for-users/README.fr.md) updated if user-facing behavior changedArchitecture decisions
Generate) and changes none of them.Proposed: ADR-____Related issues
Refs #225 (does not close it — the
ContainingKeychange from the same issue is a separate follow-up).Generated by Claude Code