g_lib

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: BSD-3-Clause Imports: 3 Imported by: 1

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 Remove added in v0.0.14

func Remove[T any](haystack []T, needle T) (result []T)

Remove will take 'needle' from 'haystack' if it matches based on reflect.DeepEqual

func RemoveAt added in v0.0.12

func RemoveAt[T any](slice []T, pos int) []T

RemoveAt removes from `slice` the item at postion `pos`. If pos is out of range it returns the original `slice`.

func RemoveComparable added in v0.0.14

func RemoveComparable[T comparable](slice []T, element T) (result []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)

func Unique added in v0.0.14

func Unique[T comparable](s []T) []T

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