Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add ElementsMatch, ElementsMatchBy #586

Open
senago opened this issue Feb 3, 2025 · 0 comments
Open

Proposal: Add ElementsMatch, ElementsMatchBy #586

senago opened this issue Feb 3, 2025 · 0 comments

Comments

@senago
Copy link
Contributor

senago commented Feb 3, 2025

I often need to get to know If two slices are comprised of the same set of elements.
There's a similar helper in testify package: ElementsMatch.

The proposal:

// ElementsMatch returns true if lists
// contain the same set of elements (including empty set).
// 
// If there are duplicate elements,
// the number of appearances of each of them in both lists should match.
func ElementsMatch[T comparable, Slice ~[]T](list1 Slice, list2 Slice) bool

// ElementsMatchBy returns true if lists
// contain the same set of elements' keys (including empty set).
// 
// If there are duplicate keys,
// the number of appearances of each of them in both lists should match.
func ElementsMatchBy[T any, K comparable](list1 []T, list2 []T, iteratee func(item T) K) bool

To implement ElementsMatch we could make use of Keyify.
To implement ElementsMatchBy some new code is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant