Open jimmyfrasche opened 19 hours ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
A minor nit: in order to correspond to cmp.Compare
, the implementation in the cmp package should be something like
func Cmp[T comparable](a, b T) bool {
if isNaN(a) && isNaN(b) {
return true
}
return a == b
}
Proposal Details
I find myself writing this a lot lately. Sometimes multiple times in a module because I don't want to export it or bother with creating
internal/
packages just for this.This comes up whenever you have
Op
andOpFunc
where the latter variant takes an equality function. The body ofOp
just callsOpFunc
with some local copy of the proposed.Even with the shortest possible syntax proposed in #21498 this would still be
(a, b) => a == b
vscmp.Equal[T]
andT
would often be inferred as this is basically always used as the argument to a function.