-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: slices: add difference function #58730
Comments
This sounds like an operation that would suit a set datatype better than slices. |
This seems to have a very specific idea of "difference". |
If this isn't going to preserve ordering, I see no reason that this shouldn't just be handled, eventually, as something like set1 := set.New(slice1...)
diff := set1.Sub(set.New(slice2)...)
diffslice := diff.Slice() That's not much more difficult, is more obvious about what it's doing and all the implicit allocations, and gives the caller significantly more control. |
This is filter of s1 but using a set provided as a slice in s2 instead of a predicate function. |
This proposal has been added to the active column of the proposals project |
In addition to the good arguments about this really being a set operation... For a function named |
Based on the discussion above, this proposal seems like a likely decline. |
This seems like a better proposal. Thanks |
No change in consensus, so declined. |
There are many scenarios where it is necessary to obtain the difference of two slices. At present, the more common method is to create a new utils package in the project and write the method implementation in it. Now that the Go standard library has a new slices package, it is recommended to add an API:
Similar as golang/exp#50
The full implementation golang/exp#60
The text was updated successfully, but these errors were encountered: