cmp

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OrderLess is an Ordering where a compared value is less than another
	OrderLess = Order(-1)

	// OrderEqual is an Ordering where a compared value is equal to another
	OrderEqual = Order(0)

	// OrderGreater is an Ordering where a compared value is greater than another
	OrderGreater = Order(1)
)

Variables

This section is empty.

Functions

func Compare added in v0.4.0

func Compare[T Ordered](lhs T, rhs T) int

func Equal

func Equal[T comparable](lhs T, rhs T) bool

func Greater

func Greater[T Ordered](lhs T, rhs T) bool

func GreaterThan added in v0.4.0

func GreaterThan[T Ordered](lhs T, rhs T) bool

func Less

func Less[T Ordered](lhs T, rhs T) bool

func LessThan added in v0.4.0

func LessThan[T Ordered](lhs T, rhs T) bool

func MaxBy

func MaxBy[A any, F ~func(A, A) Order](cmp F, lhs, rhs A) A

MaxBy calculates the maximum value of two values by a given function.

func MaxByKey

func MaxByKey[A any, F ~func(A) K, K Ordered](key F, lhs, rhs A) A

MaxByKey calculates the maximum value of two values by a key function.

func MaxOrdered

func MaxOrdered[A Ordered](lhs, rhs A) A

MaxOrdered calculates the maximum value of two ordered values.

func MinBy

func MinBy[A any, F ~func(A, A) Order](cmp F, lhs, rhs A) A

MinBy calculates the minimum value of two values by a given function.

func MinByKey

func MinByKey[A any, F ~func(A) K, K Ordered](key F, lhs, rhs A) A

MinByKey calculates the minimum value of two values by a key function.

func MinOrdered

func MinOrdered[A Ordered](lhs, rhs A) A

MinOrdered calculates the minimum value of two ordered values.

func NotEqual added in v0.4.0

func NotEqual[T comparable](lhs T, rhs T) bool

Types

type Eq

type Eq[A any] interface {
	PartialEq[A]
}

Eq is a type that represents an equality comparison.

see: [Eq](https://en.wikipedia.org/wiki/Equivalence_relation)

type Ord

type Ord[A any] interface {
	Eq[A]
	PartialOrd[A]
	Cmp(A) Order
}

Ord is a type that represents an ordered value.

see: [Ord](https://en.wikipedia.org/wiki/Total_order)

type Order

type Order int // -1, 0, 1

func (Order) IsEq added in v0.4.0

func (o Order) IsEq() bool

func (Order) IsGe added in v0.4.0

func (o Order) IsGe() bool

func (Order) IsGt added in v0.4.0

func (o Order) IsGt() bool

func (Order) IsLe added in v0.4.0

func (o Order) IsLe() bool

func (Order) IsLt added in v0.4.0

func (o Order) IsLt() bool

func (Order) IsNe added in v0.4.0

func (o Order) IsNe() bool

func (Order) String added in v0.4.0

func (o Order) String() string

type Ordered added in v0.4.0

type Ordered = cmp.Ordered

type PartialEq

type PartialEq[A any] interface {
	Eq(A) bool
	Ne(A) bool
}

PartialEq is a type that represents a partial equality comparison.

see: [PartialEq](https://en.wikipedia.org/wiki/Partial_equivalence_relation)

type PartialOrd

type PartialOrd[A any] interface {
	PartialCmp(A) optional.Optional[Order]
	Lt(A) bool
	Le(A) bool
	Gt(A) bool
	Ge(A) bool
}

PartialOrd is a type that represents a partially ordered value.

see: [PartialOrd](https://en.wikipedia.org/wiki/Partially_ordered_set)

Jump to

Keyboard shortcuts

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