cmp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

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

	// Equal is an Ordering where a compared value is equal to another
	Equal = order(0)

	// Greater is an Ordering where a compared value is greater than another
	Greater = order(1)
)

Variables

This section is empty.

Functions

func EqByKey

func EqByKey[A any, F func(A) K, K Eq[K]](f F, lhs, rhs A) bool

EqByKey calculates the equality of two values by a key function.

func Max

func Max[A Ord[A]](lhs A, rhs A) A

Max calculates the maximum value of two values.

func MaxBy

func MaxBy[A any, F func(A, A) Ordering](compare 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 Ord[K]](f F, lhs, rhs A) A

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

func MaxOrdered

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

MaxOrdered calculates the maximum value of two ordered values.

func Min

func Min[A Ord[A]](lhs, rhs A) A

Min calculates the minimum value of two values.

func MinBy

func MinBy[A any, F func(A, A) Ordering](compare 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 Ord[K]](f F, lhs, rhs A) A

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

func MinOrdered

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

MinOrdered calculates the minimum value of two ordered values.

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 EqFunc

type EqFunc[A any] func(lhs A, rhs A) bool

EqFunc is a function that returns a bool.

type Ord

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

Ord is a type that represents an ordered value.

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

type OrdFunc

type OrdFunc[A any] func(lhs A, rhs A) Ordering

OrdFunc is a function that returns an Ordering.

type Ordering

type Ordering interface {
	IsEq() bool
	IsNe() bool
	IsLt() bool
	IsLe() bool
	IsGt() bool
	IsGe() bool
	fmt.Stringer
	// contains filtered or unexported methods
}

Ordering is a type that represents the ordering of two values.

func CmpByKey

func CmpByKey[A any, F func(A) K, K Ord[K]](f F, lhs, rhs A) Ordering

CmpByKey calculates the comparison of two values by a key function.

func Order

func Order(lhs, rhs Ordering) Ordering

Order is a function that returns an Ordering of two Ordering.

 result table is:
		| lhs\rhs | Less    |  Equal  | Greater |
		|---------|---------|---------|---------+
		| Less    | Equal   | Less    | Less    |
		| Equal   | Greater | Equal   | Less    |
		| Greater | Greater | Greater | Equal   |

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[Ordering]
	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