g_lib

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: BSD-3-Clause Imports: 2 Imported by: 2

README

# Go 1.18 Library with Basic Generic Functions and Tests

1. Min, Max
2. MinArray, MaxArray
3. String keys for a Map
4. Sorting of Type
5. Search a slice for a value
6. Convert map[string]value to []SliceType with name/value



Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T SignedNumeric](a T) T

func EqualSlice added in v0.0.7

func EqualSlice[T comparable](s, t []T) bool

func GetMapKeys added in v0.0.6

func GetMapKeys[K comparable, V any](m map[K]V) []K

func IfTrue added in v0.0.10

func IfTrue[T any](on bool, a T, b T) (rv T)

func InArray

func InArray[T comparable](needle T, haystack []T) bool

InArray uses Dijkstra's "L" algorythm to search 'haystack' for 'needle'. "L" is the linear search algorythm. Exampel of Use:

func KeysForStringMap

func KeysForStringMap[T any](aMap map[string]T) (rv []string)

func LocationInArray

func LocationInArray[T comparable](needle T, haystack []T) int

func Max

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

func MaxArray

func MaxArray[T constraints.Ordered](a []T) (rv T)

func Min

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

func MinArray

func MinArray[T constraints.Ordered](a []T) (rv T)

func SortSlice added in v0.0.6

func SortSlice[T constraints.Ordered](s []T)

func SortedKeysForStringMap added in v0.0.10

func SortedKeysForStringMap[T any](aMap map[string]T) (rv []string)

Types

type Numeric

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type SignedInteger

type SignedInteger interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Signed is a constraint with a type set of all signed integer types.

type SignedNumeric

type SignedNumeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~float32 | ~float64
}

SignedNumeric is a constraint with a type set of all signed types.

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned is a constraint with a type set of all unsigned integer types.

Jump to

Keyboard shortcuts

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