google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

Adding new ThreeWayComparable interface #457

Closed SamWheating closed 1 year ago

SamWheating commented 1 year ago

Re: https://github.com/google/starlark-go/issues/356

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: