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 Coalesce[M Measurable[any]](args ...M) M
- func ContainsString(items []string, item string) bool
- func ContainsStringEqualFold(items []string, item string) bool
- func Float64SlicesEqual(a, b []float64) bool
- func Int64SlicesEqual(a, b []int64) bool
- func MapStringSlice(items []string, mapFn func(in string) string) []string
- func NumbersCoalesce[T ~int | ~int32 | ~uint | ~uint32 | ~int64 | ~uint64](items ...T) T
- func NvlString(items ...string) string
- func Prefixed(prefix string, items []string) []string
- func Quoted(items []string) []string
- func Select[T any](cond bool, a, b T) T
- 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 StringsCoalesce(str ...string) string
- func Suffixed(suffix string, items []string) []string
- func Uint64SlicesEqual(a, b []uint64) bool
- func UniqueStrings(dups []string) []string
- type Measurable
- 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 Coalesce ¶
func Coalesce[M Measurable[any]](args ...M) M
Coalesce returns the first non-empty value
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 Float64SlicesEqual ¶
Float64SlicesEqual returns true only if the contents of the 2 slices are the same
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 NumbersCoalesce ¶
NumbersCoalesce returns the first value from the supplied list that is not 0, or 0 if there are no values that are not zero
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 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 StringsCoalesce ¶
StringsCoalesce returns the first non-empty string value
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 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 Measurable ¶
Measurable interface
type Uint64s ¶
type Uint64s []uint64
Uint64s is a slice of uint64, that knows how to be sorted, using sort.Sort