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

Add Duplicate & DuplicateBy #121

Closed
CorentinClabaut opened this issue May 2, 2022 · 1 comment · Fixed by #122
Closed

Add Duplicate & DuplicateBy #121

CorentinClabaut opened this issue May 2, 2022 · 1 comment · Fixed by #122

Comments

@CorentinClabaut
Copy link
Contributor

CorentinClabaut commented May 2, 2022

It would be useful to have:
func Duplicate[T comparable](collection []T) []T
func DuplicateBy[T any, U comparable](collection []T, iteratee func(T) U) []T

That would only return the duplicated values of the collection
.

@CorentinClabaut
Copy link
Contributor Author

@samber what do you think about that?

I know it's not usually a standard function but I thought it could be useful.
Stackoverflow contains a lot of questions about finding duplicates.

In my case it was useful to simply validate some input and write an error with the duplications if any were found.

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

Successfully merging a pull request may close this issue.

1 participant