Documentation
¶
Overview ¶
Package cmp provides types and functions related to comparing ordered values.
It is a copy of cmp with some additions. It is a strict superset and can be used as a drop-in replacement for the standard library package everywhere.
Index ¶
Constants ¶
const ( // OrderLess indicates that the first value is less than the second value. // It is the same value (-1) as returned by [cmp.Compare]. OrderLess = Order(-1) // OrderEqual indicates that the first value is equal to the second value. // It is the same value (0) as returned by [cmp.Compare]. OrderEqual = Order(0) // OrderGreater indicates that the first value is greater than the second value. // It is the same value (+1) as returned by [cmp.Compare]. OrderGreater = Order(+1) )
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare returns
-1 ([OrderLess]) if x is less than y, 0 ([OrderEqual]) if x equals y, +1 ([OrderGreater]) if x is greater than y.
For floating-point types, a NaN is considered less than any non-NaN, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.
It is the same as cmp.Compare.
func Equal ¶
Equal reports whether x is equal to y. For floating-point types, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.
func Greater ¶
Greater reports whether x is greater than y. For floating-point types, any non-NaN is considered greater than a NaN, and -0.0 is not greater than (is equal to) 0.0.
func Less ¶
Less reports whether x is less than y. For floating-point types, a NaN is considered less than any non-NaN, and -0.0 is not less than (is equal to) 0.0.
It is the same as cmp.Less.
func Or ¶
func Or[T comparable](vals ...T) T
Or returns the first of its arguments that is not equal to the zero value. If no argument is non-zero, it returns the zero value.
It is the same as cmp.Or.
Types ¶
type Ordered ¶
Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.
Note that floating-point types may contain NaN ("not-a-number") values. An operator such as == or < will always report false when comparing a NaN value with any other value, NaN or not. See the Compare function for a consistent way to compare NaN values.
It is a type alias for cmp.Ordered.