Migrate Digit, Divide, and ExceptNulls off Option#30
Merged
Conversation
Ports Digit and the numeric Divide/SafeDivide extensions away from the legacy Option<T> surface onto the TryCreate/nullable-return pattern, and introduces a nullable-reference-types-aware ExceptNulls so FilterDigits no longer has to flatten Options. - Digit now uses TryCreate/Create, implements IEquatable and IComparable against itself, byte, and int, and lives under src/StrongTypes/Digits. - Divide returns decimal? and SafeDivide delegates via `Divide ?? otherwise`. - ExceptNulls moves into src/StrongTypes/Collections with nullable T constraints for both struct and class; FilterDigits now uses it. - Legacy _Old sources and their tests are retired. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds ==, !=, <, <=, >, >= between Digit and both byte and int, in each direction, so callers can write `digit == 5` or `(byte)3 < digit` without routing through the implicit conversions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
KaliCZ
added a commit
that referenced
this pull request
Apr 19, 2026
* Migrate Digit, Divide, and ExceptNulls off Option Ports Digit and the numeric Divide/SafeDivide extensions away from the legacy Option<T> surface onto the TryCreate/nullable-return pattern, and introduces a nullable-reference-types-aware ExceptNulls so FilterDigits no longer has to flatten Options. - Digit now uses TryCreate/Create, implements IEquatable and IComparable against itself, byte, and int, and lives under src/StrongTypes/Digits. - Divide returns decimal? and SafeDivide delegates via `Divide ?? otherwise`. - ExceptNulls moves into src/StrongTypes/Collections with nullable T constraints for both struct and class; FilterDigits now uses it. - Legacy _Old sources and their tests are retired. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Add Digit cross-type operators for byte and int Adds ==, !=, <, <=, >, >= between Digit and both byte and int, in each direction, so callers can write `digit == 5` or `(byte)3 < digit` without routing through the implicit conversions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <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.
Summary
Digitnow follows theTryCreate/Createpattern (noOption), lives undersrc/StrongTypes/Digits/, and implementsIEquatable+IComparableagainst itself,byte, andint.Dividereturnsdecimal?;SafeDivideis a thinDivide(b) ?? otherwisewrapper. Both live in the newsrc/StrongTypes/Numbers/NumberExtensions.cs.ExceptNullsis reintroduced as an NRT-aware extension insrc/StrongTypes/Collections/IEnumerableExtensions.cs(where T : structonIEnumerable<T?>andwhere T : classonIEnumerable<T?>).FilterDigitsnow uses it in place ofFlatten(Option<T>).Digit_Old,DigitExtensions_Old,NumberExtensions_Oldand their_Oldtests are retired; the duplicateExceptNullsis removed from the legacyIEnumerableExtensions_Generic_Oldpartial.On
record structI kept
Digitas a plainreadonly struct. Arecord structwould auto-generateEquals(Digit)/GetHashCode/==/!=, but we still need to hand-writeIEquatable<byte>,IEquatable<int>, all threeIComparable<T>overloads, the ordering operators, and a customToString()(the synthesized recordToStringprintsDigit { Value = 5 }). Once you add all that, the savings are small, and the remaining surface reads more uniformly against the other strong types (NonEmptyString, the numeric wrappers) when it's a regular struct with explicit equality.Test plan
dotnet buildclean (0 warnings, 0 errors)dotnet test src/StrongTypes.Tests/StrongTypes.Tests.csproj— 470 passed