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: x/exp/slices: add Set #57241

Closed
k-x7 opened this issue Dec 11, 2022 · 2 comments
Closed

proposal: x/exp/slices: add Set #57241

k-x7 opened this issue Dec 11, 2022 · 2 comments

Comments

@k-x7
Copy link

k-x7 commented Dec 11, 2022

Add a new function, slices.Set which removes all duplicate elements in a slice.

Proposed Signature:

func Set[E comparable](s []E)

Usage:

i := []int{1, 2, 3, 1, 2, 3, 1, 4, 5, 6, 2, 1, 1, 2, 4, 7}
slices.Set(i) // i == []int{6, 3, 2, 4, 7, 1, 5} or i == []int{1, 2, 3, 4, 5, 6, 7}

The name slices.Set from the data type Set, which holds unique values, without any particular order, slices.Set might be confusing as a function name, other alternative is slices.Unique.

Examples where people asked for slimier function: 1, 2, 3

@k-x7 k-x7 added the Proposal label Dec 11, 2022
@gopherbot gopherbot added this to the Proposal milestone Dec 11, 2022
@seankhliao
Copy link
Member

see the original discussion for Uniq
Duplicate of #45955

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2022
@k-x7
Copy link
Author

k-x7 commented Dec 11, 2022

Thanks @seankhliao , it was hidden in the long issue.

for anyone looking for Uniq or Set please see: #47203 (comment)

i := []int{1, 2, 3, 1, 2, 3, 1, 4, 5, 6, 2, 1, 1, 2, 4, 7}
slices.Sort(i)
i = slices.Compact(i) // i == []int{1, 2, 3, 4, 5, 6, 7}

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

No branches or pull requests

3 participants