Documentation
¶
Overview ¶
Package collate contains comparison-related entities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CaseInsensitiveOrder = StringOrder{strings.ToLower}
CaseInsensitiveOrder is a case-insensitive StringOrder.
Functions ¶
func TimeCompare ¶ added in v0.2.0
TimeCompare compares the specified time instants. (See [Comparer.Compare] for return values.)
Types ¶
type Comparer ¶
type Comparer[T any] interface { // Compare compares the specified objects and returns negative if the first one is less than the second, // zero if the first one is equal to the second and positive if the first one is greater than the second. Compare(T, T) int }
Comparer defines a function to compare the specified objects of type T.
var TimeComparer Comparer[time.Time] = ComparerFunc[time.Time](TimeCompare)
type ComparerFunc ¶
The ComparerFunc type is an adapter to allow the use of ordinary functions as a Comparer. If f is a function with the appropriate signature, ComparerFunc(f) is a Comparer that calls f. ComparerFunc also implements the Equaler and Lesser interfaces.
func (ComparerFunc[T]) Compare ¶
func (cmpf ComparerFunc[T]) Compare(x, y T) int
Compare implements the Comparer interface.
func (ComparerFunc[T]) Equal ¶
func (cmpf ComparerFunc[T]) Equal(x, y T) bool
Equal implements the Equaler interface.
func (ComparerFunc[T]) Less ¶
func (cmpf ComparerFunc[T]) Less(x, y T) bool
Less implements the Lesser interface.
type DeepEqualer ¶
type DeepEqualer[T any] struct{}
DeepEqualer is an Equaler implementation that is a generic wrapper around reflect.DeepEqual.
func (DeepEqualer[T]) Equal ¶
func (DeepEqualer[T]) Equal(x, y T) bool
Equal implements the Equaler interface.
type Equaler ¶
type Equaler[T any] interface { // Equal reports whether the specified objects are equal. Equal(T, T) bool }
Equaler defines a function to compare the objects of type T for equality.
type EqualerFunc ¶
The EqualerFunc type is an adapter to allow the use of ordinary functions as an Equaler. If f is a function with the appropriate signature, EqualerFunc(f) is an Equaler that calls f.
func (EqualerFunc[T]) Equal ¶
func (eqf EqualerFunc[T]) Equal(x, y T) bool
Equal implements the Equaler interface.
type Lesser ¶
type Lesser[T any] interface { // Less reports whether the first object is less than the second. Less(T, T) bool }
Lesser defines a function to compare the specified objects of type T.
type LesserFunc ¶
The LesserFunc type is an adapter to allow the use of ordinary functions as a Lesser. If f is a function with the appropriate signature, LesserFunc(f) is a Lesser that calls f. LesserFunc also implements the Equaler and Comparer interfaces.
func (LesserFunc[T]) Compare ¶
func (lsf LesserFunc[T]) Compare(x, y T) int
Compare implements the Comparer interface.
func (LesserFunc[T]) Equal ¶
func (lsf LesserFunc[T]) Equal(x, y T) bool
Equal implements the Equaler interface.
func (LesserFunc[T]) Less ¶
func (lsf LesserFunc[T]) Less(x, y T) bool
Less implements the Lesser interface.
type MapEqualer ¶ added in v0.6.0
type MapEqualer[M ~map[K]V, K, V comparable] struct{}
MapEqualer type implements the Equaler interface for maps.
func (MapEqualer[M, K, V]) Equal ¶ added in v0.6.0
func (MapEqualer[M, K, V]) Equal(m1, m2 M) bool
Equal implements the Equaler interface.
type Order ¶
Order type implements the Equaler, Lesser and Comparer interfaces for ordered types.
type SliceOrder ¶ added in v0.5.0
SliceOrder type implements the Equaler, Lesser and Comparer interfaces for slices of ordered elements.
func (SliceOrder[S, E]) Compare ¶ added in v0.5.0
func (SliceOrder[S, E]) Compare(x, y S) int
Compare implements the Comparer interface.
func (SliceOrder[S, E]) Equal ¶ added in v0.5.0
func (SliceOrder[S, E]) Equal(x, y S) bool
Equal implements the Equaler interface.
func (SliceOrder[S, E]) Less ¶ added in v0.5.0
func (SliceOrder[S, E]) Less(x, y S) bool
Less implements the Lesser interface.
type StringOrder ¶ added in v0.3.0
StringOrder type implements the Equaler, Lesser and Comparer interfaces for strings modified according to the mapping function, if any.
func (StringOrder) Compare ¶ added in v0.3.0
func (so StringOrder) Compare(x, y string) int
Compare implements the Comparer interface.