package
1.2.4
Repository: https://github.com/ccheers/xpkg.git
Documentation: pkg.go.dev

# README

cmpx

import "github.com/ccheers/xpkg/generic/cmpx"

Index

func Clamp

func Clamp[T constraints.Ordered](x, lo, hi T) T

Clamp returns x constrained within [lo:hi] range. If x compares less than lo, returns lo; otherwise if hi compares less than x, returns hi; otherwise returns v.

func Compare

func Compare[T comparable](a, b T, less LessFn[T]) int

Compare uses a less function to determine the ordering of 'a' and 'b'. It returns:

* -1 if a < b

* 1 if a > b

* 0 if a == b

func Equals

func Equals[T comparable](a, b T) bool

Equals wraps the '==' operator for comparable types.

func Less

func Less[T constraints.Ordered](a, b T) bool

Less wraps the '<' operator for ordered types.

func Max

func Max[T constraints.Ordered](a, b T) T

Max returns the max of a and b.

func MaxFunc

func MaxFunc[T comparable](a, b T, less LessFn[T]) T

MaxFunc returns the max of a and b using the less func.

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the min of a and b.

func MinFunc

func MinFunc[T comparable](a, b T, less LessFn[T]) T

MinFunc returns the min of a and b using the less func.

type EqualsFn

EqualsFn is a function that returns whether 'a' and 'b' are equal.

type EqualsFn[T comparable] func(a, b T) bool

type HashFn

HashFn is a function that returns the hash of 't'.

type HashFn[T comparable] func(t T) uint64

type LessFn

LessFn is a function that returns whether 'a' is less than 'b'.

type LessFn[T comparable] func(a, b T) bool

Generated by gomarkdoc

# Functions

Clamp returns x constrained within [lo:hi] range.
Compare uses a less function to determine the ordering of 'a' and 'b'.
Equals wraps the '==' operator for comparable types.
Less wraps the '<' operator for ordered types.
Max returns the max of a and b.
MaxFunc returns the max of a and b using the less func.
Min returns the min of a and b.
MinFunc returns the min of a and b using the less func.

# Type aliases

EqualsFn is a function that returns whether 'a' and 'b' are equal.
HashFn is a function that returns the hash of 't'.
LessFn is a function that returns whether 'a' is less than 'b'.