compare

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package compare contains support functions for comparison of values.

Comparison Functions

For the purposes of this package, a comparison function takes two values A and B of a type and reports their relative order, returning:

-1 if A precedes B,
 0 if A and B are equivalent,
+1 if A follows B

Comparison functions are expected to implement a strict weak ordering. Unless otherwise noted, any negative value is accepted in place of -1, and any positive value in place of 1.

Less Functions

For the purposes of this package, a less function takes two values A and B of a type and reports whether A precedes B in relative order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v0.21.4

func Bool(a, b bool) int

Bool is a comparison function for bool values that orders false before true.

func FromLessFunc added in v0.8.2

func FromLessFunc[T any](less func(a, b T) bool) func(a, b T) int

FromLessFunc converts a less function, which reports whether its first argument precedes its second in an ordering relation, into a comparison function on that same relation.

func Reversed added in v0.13.4

func Reversed[T any](c func(a, b T) int) func(a, b T) int

Reversed returns a comparison function that orders its elements in the reverse of the ordering expressed by c.

func Time added in v0.13.4

func Time(a, b time.Time) int

Time is a comparison function for time.Time values that orders earlier times before later ones.

func ToLessFunc added in v0.8.3

func ToLessFunc[T any](cmp func(a, b T) int) func(a, b T) bool

ToLessFunc converts a comparison function into a less function on the same relation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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