collate

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 6 Imported by: 4

README

collate

Go Reference

Comparison-related entities.

Documentation

Overview

Package collate contains comparison-related entities.

Index

Constants

This section is empty.

Variables

View Source
var CaseInsensitiveOrder = StringOrder{strings.ToLower}

CaseInsensitiveOrder is a case-insensitive StringOrder.

Functions

func TimeCompare added in v0.2.0

func TimeCompare(t1, t2 time.Time) int

TimeCompare compares the specified time instants. (See [Comparer.Compare] for return values.)

func TimeEqual added in v0.2.0

func TimeEqual(t1, t2 time.Time) bool

TimeEqual reports whether 't1' and 't2' represent the same time instant.

func TimeLess added in v0.2.0

func TimeLess(t1, t2 time.Time) bool

TimeLess reports whether the time instant 't1' is before 't2'.

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.

TimeComparer is a Comparer for time.Time.

type ComparerFunc

type ComparerFunc[T any] func(T, T) int

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.

var TimeEqualer Equaler[time.Time] = EqualerFunc[time.Time](TimeEqual)

TimeEqualer is an Equaler for time.Time.

type EqualerFunc

type EqualerFunc[T any] func(T, T) bool

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.

var TimeLesser Lesser[time.Time] = LesserFunc[time.Time](TimeLess)

TimeLesser is a Lesser for time.Time.

type LesserFunc

type LesserFunc[T any] func(T, T) bool

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

type Order[T cmp.Ordered] struct{}

Order type implements the Equaler, Lesser and Comparer interfaces for ordered types.

func (Order[T]) Compare

func (Order[T]) Compare(x, y T) int

Compare implements the Comparer interface.

func (Order[T]) Equal

func (Order[T]) Equal(x, y T) bool

Equal implements the Equaler interface.

func (Order[T]) Less

func (Order[T]) Less(x, y T) bool

Less implements the Lesser interface.

type SliceOrder added in v0.5.0

type SliceOrder[S ~[]E, E cmp.Ordered] struct{}

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

type StringOrder struct {
	Mapping func(string) string
}

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.

func (StringOrder) Equal added in v0.3.0

func (so StringOrder) Equal(x, y string) bool

Equal implements the Equaler interface.

func (StringOrder) Less added in v0.3.0

func (so StringOrder) Less(x, y string) bool

Less implements the Lesser interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL