This adds a new TotallyOrdered interface, similar to Comparable which returns an integer representing the <, ==, > relation between values. The CompareDepth function has been to updated check for this interface and handle this return style if applicable.
Also refactors int, float, time.Time and time.Duration types to use the new interface.
The previous Comparable interface will have to be maintained, not just for API compatibility but also for types which define equality/inequality but not ordering (for example, structs)
Open questions:
Is the ThreeWayCompareSameType name too verbose? I was thinking about overloading the name CompareSameType but that felt like it would get confusing. -> Yes, change to TotallyOrdered
Should I also update the other orderable types (float, str, list, etc) to use this interface in this PR? -> Yes.
Re: https://github.com/google/starlark-go/issues/356
This adds a new
TotallyOrdered
interface, similar toComparable
which returns an integer representing the <, ==, > relation between values. TheCompareDepth
function has been to updated check for this interface and handle this return style if applicable.Also refactors
int
,float
,time.Time
andtime.Duration
types to use the new interface.The previous
Comparable
interface will have to be maintained, not just for API compatibility but also for types which define equality/inequality but not ordering (for example, structs)Open questions:
TotallyOrdered