Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Max ¶
func Max[T Ordered](first T, rest ...T) T
Max returns the largest value among a fixed number of arguments of type Ordered. At least one argument must be passed, and it returns that if it's the only one. It compares all the provided values and returns the maximum value.
max := Max(3, 5, 2) // max is 5
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/gx" ) func main() { // Finding the max value maxInt := gx.Max(3, 1, 4, 2) // maxInt will be 4 maxFloat := gx.Max(5.1, 2.3, 8.7) // maxFloat will be 8.7 maxStr := gx.Max("apple", "banana") // maxStr will be "banana" fmt.Println(maxInt, maxFloat, maxStr) }
Output: 4 8.7 banana
func Min ¶
func Min[T Ordered](first T, rest ...T) T
Min returns the smallest value among a fixed number of arguments of type Ordered. At least one argument must be passed, and it returns that if it's the only one. It compares all the provided values and returns the minimum value.
min := Min(3, 5, 2) // min is 2
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/gx" ) func main() { // Finding the min value minInt := gx.Min(3, 1, 4, 2) // minInt will be 1 minFloat := gx.Min(5.1, 2.3, 8.7) // minFloat will be 2.3 minStr := gx.Min("apple", "banana") // minStr will be "apple" fmt.Println(minInt, minFloat, minStr) }
Output: 1 2.3 apple
Types ¶
type Ordered ¶
type Ordered interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string }
Ordered is a constraint that allows any ordered type, i.e., types that support comparison operators like <, <=, >=, and >. This includes various numeric types (integers and floats) and strings.