Add DifferenceBy to compute differences by a derived key AND align Difference naming#867
Open
chg1f wants to merge 2 commits into
Open
Add DifferenceBy to compute differences by a derived key AND align Difference naming#867chg1f wants to merge 2 commits into
chg1f wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #867 +/- ##
==========================================
+ Coverage 92.03% 92.06% +0.03%
==========================================
Files 32 32
Lines 6177 6203 +26
==========================================
+ Hits 5685 5711 +26
Misses 389 389
Partials 103 103
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Describe your changes
This PR adds
DifferenceBy, a new helper that computes the asymmetric difference between two collections using a custom key selector. It fills the gap next toDifferenceandIntersectBy: callers can now compare slices of non-comparable values, or compare values by a derived identity, without having to manually project and diff intermediate slices.DifferenceBykeeps the same directional semantics asDifference. The first returned slice contains elements fromleftwhose keys are absent fromright, and the second returned slice contains elements fromrightwhose keys are absent fromleft. The implementation preserves the input order of each side and keeps duplicates when their extracted keys are not present on the other side, which matches the current behavior and mental model ofDifference.This PR also includes a follow-up naming cleanup for
Difference. The behavior ofDifferenceis unchanged, but its inputs and outputs now use the same directional terminology asDifferenceBy:left,right,notInRight, andnotInLeft. I included this cleanup in the same PR not only to keep the base helper and its newByvariant consistent across implementation, tests, examples, and documentation, but also because the renamed return values make it more concise and explicit what each returned slice contains.In addition to the core implementation, this PR updates the related tests, adds an example to
lo_example_test.go, updates the README entries for both helpers, and adds thedocs/datapage forDifferenceBywhile aligning theDifferencepage with the new terminology. This keeps the public API surface, examples, and generated helper metadata in sync.Validation:
go test ./...node docs/scripts/check-similar-keys-exist-in-directory.jsnode docs/scripts/check-cross-references.jsgolangci-lint fmt --diff -E gofumpt intersect.goChecklist before requesting a review