-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
text/template: make "eq" support all comparable types #33740
Comments
I'm not sure I get what you're proposing; the title seems to suggest Go's See https://golang.org/pkg/reflect/#DeepEqual and https://golang.org/ref/spec#Comparison_operators. |
Hey @mvdan, sorry for not being clear. About the example I've added above (with Is there any objection about adding this support? or, at least part of it (pointers only)? If not, I would like to contribute my changes. |
CC @robpike |
It's too bad that comparison of interface values panic if the types aren't comparable, and there is no way to avoid that bar catching the panic. If we were willing to catch the panic, which would be expensive but probably very rare in practice, we could just do That might be the right solution. It wouldn't require baking in lots of information about what types are comparable. |
Change https://golang.org/cl/193837 mentions this issue: |
Given @robpike's comment above, this sounds like a likely accept. |
No comments, so proposal accepted. |
The current
eq
function is limited only to "basic types", and it does not support other Go types that are comparable, like pointers or structs.Also, it's not possible to decorate it, because it's private. Setting
"eq": reflect.DeepEqual
won't provide the same functionally, because cases like this:https://play.golang.org/p/zTg33Lggq0f
My current solution is just copying the current code from
text/template/funcs.go
, and adding the support by myself.I would like to hear what others think about this, because it feels like a basic functionality that is missing when working with Go types.
If this proposal will be accepted, I will be more than happy to contribute my changes.
The text was updated successfully, but these errors were encountered: