cmp

package
v1.0.77 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Max added in v1.0.74

func Max[T cmp.Ordered](t ...T) T

Max returns the maximum value among the given values. The values must be of a type that implements the cmp.Ordered interface for comparison.

func MaxBy added in v1.0.75

func MaxBy[T any](fn func(x, y T) Ordering, t ...T) T

MaxBy finds the maximum value in the collection t according to the provided comparison function fn. It returns the maximum value found.

func Min added in v1.0.74

func Min[T cmp.Ordered](t ...T) T

Min returns the minimum value among the given values. The values must be of a type that implements the cmp.Ordered interface for comparison.

func MinBy added in v1.0.75

func MinBy[T any](fn func(x, y T) Ordering, t ...T) T

MinBy finds the minimum value in the collection t according to the provided comparison function fn. It returns the minimum value found.

Types

type Ordering added in v1.0.72

type Ordering int

Ordering is the result of a comparison between two values.

const (
	Less    Ordering = iota - 1 // Less represents an ordered value where a compared value is less than another.
	Equal                       // Equal represents an ordered value where a compared value is equal to another.
	Greater                     // Greater represents an ordered value where a compared value is greater than another.
)

func Cmp

func Cmp[T cmp.Ordered](x, y T) Ordering

Cmp compares two ordered values and returns the result as an Ordering value.

func (Ordering) IsEq added in v1.0.75

func (o Ordering) IsEq() bool

IsEq returns true if the Ordering value is Equal.

func (Ordering) IsGt added in v1.0.75

func (o Ordering) IsGt() bool

IsGt returns true if the Ordering value is Greater.

func (Ordering) IsLt added in v1.0.75

func (o Ordering) IsLt() bool

IsLt returns true if the Ordering value is Less.

func (Ordering) Reverse added in v1.0.72

func (o Ordering) Reverse() Ordering

Reverse reverses the ordering.

func (Ordering) String added in v1.0.72

func (o Ordering) String() string

String returns the string representation of the Ordering value.

func (Ordering) Then added in v1.0.72

func (o Ordering) Then(other Ordering) Ordering

Then returns the receiver if it's equal to Equal, otherwise returns the receiver.

Jump to

Keyboard shortcuts

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