Documentation ¶
Index ¶
- func DefaultPend[T any](x, y T) func() int
- func Equal[T any](a, b T) bool
- func Or(comps ...func() int) int
- type Comparable
- type Comparer
- func Bool() Comparer[bool]
- func ComparableComparer[T Comparable[T]]() Comparer[T]
- func Default[T any]() Comparer[T]
- func Descender[T any](cmp Comparer[T]) Comparer[T]
- func Duration() Comparer[time.Duration]
- func Epsilon[T Num](epsilon T) Comparer[T]
- func FromLess[T any](less IsLessThan[T]) Comparer[T]
- func Ordered[T cmp.Ordered]() Comparer[T]
- func Slice[S ~[]T, T any](elemCmp Comparer[T]) Comparer[S]
- func Time() Comparer[time.Time]
- type Equatable
- type IsLessThan
- type Num
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPend ¶ added in v0.5.3
DefaultPend creates a default comparison and pends comparing the two given values until the returned method is called.
func Equal ¶
Equal determines if the two values are equal.
This will check if the objects are Equatable, otherwise it will fallback to a DeepEqual. This will not check for Equatable within a slice, array, map, etc only in the top level object.
This will not check for Comparable types. Any struct that implements Comparable should also implement Equatable where both agree.
Types ¶
type Comparable ¶
type Comparable[T any] interface { // CompareTo returns a comparison result of this object and the given object. // // The comparison results should be: // `< 0` if this is less than the given other, // `== 0` if this equals the given other, // `> 0` if this is greater than the given other. CompareTo(other T) int }
Comparable is an object which can be compared against another object.
The given T variable type is typically the type that is implementing this interface.
type Comparer ¶
Comparer returns the comparison result between the two given values.
The comparison results should be: `< 0` if x is less than y, `== 0` if x equals y, `> 0` if x is greater than y.
func Bool ¶
Bool is a comparer that compares the given boolean values.
| x | y | result | |:---:|:---:|:------:| | F | F | 0 | | F | T | -1 | | T | F | 1 | | T | T | 0 |
func ComparableComparer ¶
func ComparableComparer[T Comparable[T]]() Comparer[T]
ComparableComparer returns a comparer which compares the given comparable type.
func Default ¶
Default tries to create a comparer for the given type. If a comparer isn't able to be created, this will return nil.
func Descender ¶
Descender returns a comparer which negates the given comparer.
Typically negating a comparer will change a sort from ascending to descending.
func Epsilon ¶
Epsilon returns an epsilon comparer which compares the given floating point types.
An epsilon comparator should be used when comparing calculated floating point numbers since calculations may accrue small errors and make the actual value very close to the expected value but not exactly equal. The two floating point values are equal if very close to each other. The values must be within the given epsilon to be considered equal.
The given epsilon must be greater than zero. If the epsilon is less than or equal to zero, this will fallback to an ordered comparer.
func FromLess ¶
func FromLess[T any](less IsLessThan[T]) Comparer[T]
FromLess returns a comparer which compares two values using a IsLessThan function to perform the comparison.
func (Comparer[T]) Pend ¶
Pend will wait to perform the given comparison until the returned method is called. This is designed to help with `Or`.
func (Comparer[T]) Reverse ¶
Reverse gets a comparer that performs the opposite comparison. This makes a typical ascending sort into a descending sort.
func (Comparer[T]) ToLess ¶
func (cmp Comparer[T]) ToLess() IsLessThan[T]
ToLess gets an IsLessThan for this comparer.
type Equatable ¶
type Equatable interface { // Equals returns true if this object and the given object are equal. Equals(other any) bool }
Equatable is an object which can be checked for equality against another object.
type IsLessThan ¶
IsLessThan returns true if the given x is less than the given y, otherwise false.