Documentation
¶
Overview ¶
Package slices provides common slice operations (equal, contains, unique, etc.).
Package slices provides additional slice functions on common slice types
Index ¶
- func BoolSlicesEqual(a, b []bool) booldeprecated
- func ByteSlicesEqual(a, b []byte) booldeprecated
- func CloneStrings(src []string) []stringdeprecated
- func Contains[T comparable](arr []T, val T) booldeprecated
- func ContainsString(items []string, item string) booldeprecated
- func ContainsStringEqualFold(items []string, item string) bool
- func Deduplicate[E comparable](slice []E) []E
- func Float64SlicesEqual(a, b []float64) booldeprecated
- func HashStrings(values ...string) stringdeprecated
- func Int64SlicesEqual(a, b []int64) booldeprecated
- func MapStringSlice(items []string, mapFn func(in string) string) []string
- func NvlString(items ...string) stringdeprecated
- func Prefixed(prefix string, items []string) []string
- func Quoted(items []string) []string
- func Replace[E comparable](slice []E, old, newVal E)
- func StringArrayToMap(arr []string) (map[string]string, error)
- func StringContainsOneOf(item string, items []string) bool
- func StringSlicesEqual(a, b []string) booldeprecated
- func StringStartsWithOneOf(value string, items []string) bool
- func StringUpto(str string, maxLen int) string
- func StringsSafeSplit(s, sep string) []string
- func Suffixed(suffix string, items []string) []string
- func Truncate[T any](arr []T, maxLen uint) []T
- func Uint64SlicesEqual(a, b []uint64) booldeprecated
- func UniqueStrings(dups []string) []string
- type Uint64sdeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolSlicesEqual
deprecated
func ByteSlicesEqual
deprecated
func CloneStrings
deprecated
func Contains
deprecated
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.
Deprecated: use slices.Contains from the standard library.
func ContainsString
deprecated
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.
Deprecated: use slices.Contains from the standard library.
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
deprecated
func HashStrings
deprecated
added in
v0.4.1
HashStrings returns the base64 SHA-1 of a series of string values. Adjacent strings are concatenated with no delimiter, so HashStrings("ab", "c") equals HashStrings("a", "bc").
Deprecated: SHA-1 is not a safe digest. For a non-cryptographic fingerprint use values.XXH3HashArgs128Hex. For integrity use crypto/sha256 with explicit length prefixes. Do not change this function: stored hashes would break.
func Int64SlicesEqual
deprecated
func MapStringSlice ¶
MapStringSlice returns a new slices of strings that is the result of applies mapFn to each string in the input slice.
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, newVal 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
deprecated
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 StringsSafeSplit ¶ added in v0.15.80
StringsSafeSplit splits a string into a slice of strings, removing whitespaces and empty strings.
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
deprecated
func UniqueStrings ¶
UniqueStrings removes duplicates from the given list
Types ¶
type Uint64s
deprecated
type Uint64s []uint64
Uint64s is a slice of uint64, that knows how to be sorted, using sort.Sort.
Deprecated: use slices.Sort on []uint64 from the standard library.