Documentation
¶
Index ¶
- func Abs[T Number](v T) T
- func Clamp[T Number](value T, lower T, upper T) T
- func DerefOrValue[T any](v *T, defaultVal T) *T
- func Max[T ComparableNumber](v T, vs ...T) T
- func Min[T ComparableNumber](v T, vs ...T) T
- func Pointer[T any](v T) *T
- func ValueOrDefault[T comparable](v T, defaultVal T) T
- type ComparableNumber
- type Number
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clamp ¶ added in v0.1.22
func Clamp[T Number](value T, lower T, upper T) T
Clamp returns value if it's in the range [lower, upper], otherwise the closest boundary of lower and upper. NOTE: if lower > upper, then lower is always returned.
func DerefOrValue ¶
func DerefOrValue[T any](v *T, defaultVal T) *T
DerefOrValue returns v if it is not nil, otherwise returns a pointer to defaultVal.
func Max ¶
func Max[T ComparableNumber](v T, vs ...T) T
Max returns the largest value among v and vs.
func Min ¶
func Min[T ComparableNumber](v T, vs ...T) T
Min returns the smallest element among v and vs.
func ValueOrDefault ¶
func ValueOrDefault[T comparable](v T, defaultVal T) T
ValueOrDefault returns v if it isn't the default value of T, and otherwise returns defaultVal.
Types ¶
type ComparableNumber ¶
type Number ¶
type Number interface { ComparableNumber | float32 | float64 }
type Set ¶
type Set[T comparable] map[T]struct{}
func (Set[T]) Equal ¶
Equal returns true if s and s2 are of equal length and all elements contained in one set are contained in the other.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.