-
Notifications
You must be signed in to change notification settings - Fork 208
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
[FR] Change cmpopts.SortSlices param from interface{}
to func(a,b interface{}) bool
#96
Comments
Hi, I'm not sure how I can get that to work though. When the signature of the input changes from |
With generics seriously being considered for Go2, I think it be best to just leave the API as is and see how can we make it better. There are other cases where generics would have been very helpful. |
The problem I have with I had to read a couple times the documentation on how to get this to work, and sure it does, however I think saying the func takes a param type I agree this would be nicely solved by Go2, but it sounds like that's probably happening until 2 or 3 more years. |
You didn't really address the problem I posed earlier about how |
I already mentioned that in "My desired state of the world" and on the previous comment that the user would be responsible for doing type assertion in this world without generics. e.g. func (a, b interface{}) bool { a.(Foo).Val < b.(Foo).Val } |
A desired state of the world isn't helpful if it is not implementable. As it stands, I don't think there is anything actionable here. The proposed API can't work and the other alternative is to wait for generics. |
What do you mean by not implementable? Should I send a PR? Maybe I'm not explaining myself properly. Right now the API accepts an Could you clarify why is having no types better than having some types and passing the responsibility of type-asserting to the user? |
|
See this example: https://play.golang.org/p/hcpppV3sJEL |
Ah... so IIUC I think that's what you tried to point out on your first reply, but it wasn't that obvious. I thought Thanks for the discussion 😃 |
I just tried using
cmpopts.SortSlices
, and I know.. there are no generics in Go yet, but I think the current signature is not intuitive.Current state of the world:
My desired state of the world:
This proposal goes against Issue #67 but we could make it work like...
The text was updated successfully, but these errors were encountered: