gx

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0

README


This package provides generic utility functions mostly for backward compatablity support of GO version 1.20

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Max

func Max[T cmp.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 cmp.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

This section is empty.

Jump to

Keyboard shortcuts

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