Documentation ¶
Overview ¶
Package slices provides additional slice functions on common slice types
Index ¶
- func BoolSlicesEqual(a, b []bool) bool
- func ByteSlicesEqual(a, b []byte) bool
- func CloneStrings(src []string) []string
- func Contains[T comparable](arr []T, val T) bool
- func ContainsString(items []string, item string) bool
- func ContainsStringEqualFold(items []string, item string) bool
- func Deduplicate[E comparable](slice []E) []E
- func Float64SlicesEqual(a, b []float64) bool
- func HashStrings(values ...string) string
- func Int64SlicesEqual(a, b []int64) bool
- func MapStringSlice(items []string, mapFn func(in string) string) []string
- func NvlString(items ...string) string
- func Prefixed(prefix string, items []string) []string
- func Quoted(items []string) []string
- func Replace[E comparable](slice []E, old, new E)
- func StringArrayToMap(arr []string) (map[string]string, error)
- func StringContainsOneOf(item string, items []string) bool
- func StringSlicesEqual(a, b []string) bool
- func StringStartsWithOneOf(value string, items []string) bool
- func StringUpto(str string, max int) string
- func Suffixed(suffix string, items []string) []string
- func Truncate[T any](arr []T, maxLen uint) []T
- func Uint64SlicesEqual(a, b []uint64) bool
- func UniqueStrings(dups []string) []string
- type Uint64s
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolSlicesEqual ¶
BoolSlicesEqual returns true only if the contents of the 2 slices are the same
func ByteSlicesEqual ¶
ByteSlicesEqual returns true only if the contents of the 2 slices are the same
func CloneStrings ¶
CloneStrings will return an independnt copy of the src slice, it preserves the distinction between a nil value and an empty slice.
func Contains ¶ added in v0.4.1
func Contains[T comparable](arr []T, val T) bool
Contains returns true if val is in arr, and false otherwise.
func ContainsString ¶
ContainsString returns true if the items slice contains a value equal to item Note that this can end up traversing the entire slice, and so is only really suitable for small slices, for larger data sets, consider using a map instead.
func ContainsStringEqualFold ¶
ContainsStringEqualFold returns true if the items slice contains a value equal to item ignoring case [i.e. using EqualFold] Note that this can end up traversing the entire slice, and so is only really suitable for small slices, for larger data sets, consider using a map instead.
func Deduplicate ¶ added in v0.4.1
func Deduplicate[E comparable](slice []E) []E
Deduplicate returns a deduplicated slice.
func Float64SlicesEqual ¶
Float64SlicesEqual returns true only if the contents of the 2 slices are the same
func HashStrings ¶ added in v0.4.1
HashStrings returns the base64 SHA-1 of a series of string values
func Int64SlicesEqual ¶
Int64SlicesEqual returns true only if the contents of the 2 slices are the same
func MapStringSlice ¶
MapStringSlice returns a new slices of strings that is the result of applies mapFn to each string in the input slice.
func NvlString ¶
NvlString returns the first string from the supplied list that has len() > 0 or "" if all the strings are empty
func Prefixed ¶
Prefixed returns a new slice of strings with each input item prefixed by the supplied prefix e.g. Prefixed("foo", []string{"bar","bob"}) would return []string{"foobar", "foobob"} the input slice is not modified.
func Quoted ¶
Quoted returns a new slice of strings where each input stream has been wrapped in quotes
func Replace ¶ added in v0.4.1
func Replace[E comparable](slice []E, old, new E)
Replace replaces all occurrences of old with new in slice.
func StringArrayToMap ¶ added in v0.4.1
func StringContainsOneOf ¶
StringContainsOneOf returns true if one of items slice is a substring of specified value.
func StringSlicesEqual ¶
StringSlicesEqual returns true only if the contents of the 2 slices are the same
func StringStartsWithOneOf ¶
StringStartsWithOneOf returns true if one of items slice is a prefix of specified value.
func StringUpto ¶
StringUpto returns the beginning of the string up to `max`
func Suffixed ¶
Suffixed returns a new slice of strings which each input item suffixed by the supplied suffix e.g. Suffixed("foo", []string{"bar","bob"}) would return []string{"barfoo", "bobfoo"} the input slice is not modified
func Truncate ¶ added in v0.4.1
Truncate returns a new slice containing the first maxLen elements of arr. If maxLen is greater than the length of arr, arr is returned.
func Uint64SlicesEqual ¶
Uint64SlicesEqual returns true only if the contents of the 2 slices are the same
func UniqueStrings ¶
UniqueStrings removes duplicates from the given list
Types ¶
type Uint64s ¶
type Uint64s []uint64
Uint64s is a slice of uint64, that knows how to be sorted, using sort.Sort