Documentation
¶
Index ¶
- Variables
- func AllInSlice[S []T, T comparable](s1, s2 S) bool
- func AnyInSlice[S []T, T comparable](s1, s2 S) (anyIn bool)
- func AsciiToLower(s any) string
- func AsciiToUpper(s any) string
- func ContainsNil(value any) (contains bool)
- func ContainsSameElements[E1, E2 any, C comparable](s1 []E1, fn1 func(E1) C, s2 []E2, fn2 func(E2) C) (same bool)
- func DedupSlicesFunc[S ~[]E, E any](s S, cmpFunc func(E, E) int) S
- func DeleteElement[T any](s []T, pos int) []T
- func DiffSlices[S ~[]E, E comparable](s1, s2 S) (diff S)
- func DiffSlicesFunc[S ~[]E, E any](s1, s2 S, idFunc func(E) string) (diff S)
- func DirExists(dir string) (exists bool, err error)
- func Empty(value any) (empty bool)
- func EnsureDir(dir string) (err error)
- func EnsureFileRemoved(file string) (err error)
- func EntryExists(entry string) (exists bool, err error)
- func FileAppendLine(line string, filename string) (err error)
- func FileExists(file string) (exists bool, err error)
- func FileReadLines(filename string) (lines []string, err error)
- func FileRemoveLine(line, filename string) (err error)
- func FileSaveLines(filename string, lines []string) (err error)
- func FilterSlices[E comparable](s []E) []E
- func GetElementFunc[E any](slice []E, isElementFn func(E) bool) (ele E, found bool)
- func GetMissingElements[E1, E2 any, C comparable](s1 []E1, fn1 func(E1) C, s2 []E2, fn2 func(E2) C) (missing []C)
- func IndentLines(n int, s string) string
- func IntersectSlice[T comparable](s1, s2 []T) (intersect []T)
- func IsValidHostName(domain Hostname) bool
- func IsValidIPv4Address(ip IPv4Address) bool
- func MakeKeysMap[K comparable](s []K) map[K]struct{}
- func MapDefault[K comparable, T any](m map[K]T, key K, def T) T
- func MapKeys[M ~map[K]V, K comparable, V any](m M) []K
- func MapValues[M ~map[K]V, K comparable, V any](m M) []V
- func MarshalJSONFile(_ Context, file string, object any) error
- func MergeSlices[S ~[]E, E cmp.Ordered](s1, s2 S) S
- func MergeSlicesFunc[S ~[]E, E any](s1, s2 S, cmpFunc func(E, E) int) S
- func Must[T any](t T, err error) T
- func MustClose(c io.Closer)
- func Ptr[T any](t T) *T
- func RemoveElementFunc[T any](slice []T, isElementFn func(T) bool) []T
- func RemoveElements[S []T, T any](slice S, startPos, count int) S
- func SlicesIntersect[T comparable](s1, s2 []T) (intersects bool)
- func SpliceElements[S []T, T any](slice S, startPos, count int, ele ...T) S
- func Title(s string) string
- func TouchFile(path string) (err error)
- func UnmarshalJSONFile(_ Context, filename string, object any) error
- type CallStack
- type Context
- type Frame
- type Hostname
- type IPv4Address
- type String
Constants ¶
This section is empty.
Variables ¶
var DefaultLanguage = language.English
Functions ¶
func AllInSlice ¶
func AllInSlice[S []T, T comparable](s1, s2 S) bool
func AnyInSlice ¶
func AnyInSlice[S []T, T comparable](s1, s2 S) (anyIn bool)
func AsciiToLower ¶
AsciiToLower lowercases ASCII strings in a manner slightly more performant than strings.ToLower().
func AsciiToUpper ¶
AsciiToUpper uppercases ASCII strings in a manner slightly more performant than strings.ToUpper().
func ContainsNil ¶
ContainsNil returns true if an interface contains nil (vs. ==nil)
func ContainsSameElements ¶
func ContainsSameElements[E1, E2 any, C comparable](s1 []E1, fn1 func(E1) C, s2 []E2, fn2 func(E2) C) (same bool)
ContainsSameElements Compares two 'value' arrays — 'value' meaning containing no elements that are references such as pointers, slices, maps or channels — and return true if they have all the same elements and no more, even if the elements are in different positions in the slice.
func DedupSlicesFunc ¶
DedupSlicesFunc removes duplicate slices based on the return value of cmpFunc
DedupSlicesFunc([]int{0,2,4,2,3,7,3,2,8},fn) => []int{0,2,4,3,7,8}
Note the example uses scalars but this is typically to be used for slices of objects
func DeleteElement ¶
func DiffSlices ¶
func DiffSlices[S ~[]E, E comparable](s1, s2 S) (diff S)
DiffSlices takes two slices and collects any elements FOUND in the 1st slice that are NOT IN the 2nd slice, e.g.
DiffSlices([]int{0,2,4,6,8},[]int{1,2,3,4,5,6,7},fn) => []int{0,8}
func DiffSlicesFunc ¶
DiffSlicesFunc takes two slices and collects any elements FOUND in the 1st slice that are NOT IN the 2nd slice, e.g.
DiffSlicesFunc([]int{0,2,4,6,8},[]int{1,2,3,4,5,6,7},fn) => []int{0,8}
Note the example uses scalars but this is typically to be used for slices of objects
func EnsureFileRemoved ¶
func EntryExists ¶
func FileAppendLine ¶
func FileExists ¶
func FileReadLines ¶
func FileRemoveLine ¶
func FileSaveLines ¶
func FilterSlices ¶
func FilterSlices[E comparable](s []E) []E
FilterSlices returns the slice with all non-zero elements removed.
FilterSlices([]string{"A", "", "CNAME"}) => []string{"A", "CNAME"}
func GetElementFunc ¶
func GetMissingElements ¶
func GetMissingElements[E1, E2 any, C comparable](s1 []E1, fn1 func(E1) C, s2 []E2, fn2 func(E2) C) (missing []C)
GetMissingElements Compares two 'value' arrays — 'value' meaning containing no elements that are references such as pointers, slices, maps or channels — and returns the elements missing in s2 that exist in s1.
func IndentLines ¶
IndentLines each line of a string by `n` number of spaces Uses tab (`\t`) is n==0
func IntersectSlice ¶
func IntersectSlice[T comparable](s1, s2 []T) (intersect []T)
IntersectSlice returns a slice containing all the elements that are in both s1 and s2.
func IsValidHostName ¶
func IsValidIPv4Address ¶
func IsValidIPv4Address(ip IPv4Address) bool
func MakeKeysMap ¶
func MakeKeysMap[K comparable](s []K) map[K]struct{}
MakeKeysMap takes a slice and returns a map[comparable]struct{} where each element from the slice becomes a map key.
func MapDefault ¶
func MapDefault[K comparable, T any](m map[K]T, key K, def T) T
MapDefault takes a map and its comparable key and returns the key's associated value if it exists but if not returns the default value passed as a 3rd parameter. element from the slice becomes a map key.
func MapKeys ¶
func MapKeys[M ~map[K]V, K comparable, V any](m M) []K
MapKeys returns the keys of the map m as a slice. The keys will be an indeterminate order.
func MapValues ¶
func MapValues[M ~map[K]V, K comparable, V any](m M) []V
MapValues returns the values of the map m as a slice. The keys will be an indeterminate order.
func MergeSlices ¶
MergeSlices takes two slices of the same element type and merges them, removing any duplicates
MergeSlices([]int{0,2,4,6,8},[]int{1,2,3,4,5,6,7},fn) => []int{0,1,2,3,4,5,6,7,8}
func MergeSlicesFunc ¶
MergeSlicesFunc takes two slices of the same element type and merges them, removing any duplicates
MergeSlicesFunc([]int{0,2,4,6,8},[]int{1,2,3,4,5,6,7},fn) => []int{0,1,2,3,4,5,6,7,8}
Note the example uses scalars but this is typically to be used for slices of objects
func RemoveElementFunc ¶
func RemoveElements ¶
func SlicesIntersect ¶
func SlicesIntersect[T comparable](s1, s2 []T) (intersects bool)
func SpliceElements ¶
Types ¶
type IPv4Address ¶
type IPv4Address string