Documentation
¶
Overview ¶
Utilities for converting, manipulating, and iterating over slices
Index ¶
- Variables
- func Append(in any, values ...any) []any
- func At(in any, index int) (any, bool)
- func Autotype(in any) []any
- func Chunks(in any, size int) [][]any
- func Compact(in any) []any
- func CompactString(in []string) []string
- func Contains(in any, value any, comparators ...CompareFunc) bool
- func ContainsAllStrings(list []string, elems ...string) bool
- func ContainsAnyString(list []string, elems ...string) bool
- func ContainsString(list []string, elem string) bool
- func Difference(first any, second any) []any
- func Each(slice any, iterFn IterationFunc) error
- func First(in any) any
- func FirstNonZero(inputs ...any) any
- func Flatten(in any) []any
- func Get(in any, index int) any
- func Intersect(a any, b any) []any
- func IntersectStrings(a []string, b []string) []string
- func Last(in any) any
- func Len(in any) int
- func Map(in any, fn MapFunc) []any
- func MapString(in any, fn MapStringFunc) []string
- func Or(in ...any) any
- func OrString(in ...string) string
- func Rest(in any) []any
- func Slice(slice any, from int, to int) []any
- func Sliceify(in any) []any
- func SplitCompact(in string, delimiter string) (out []string)
- func SplitTrimSpaceCompact(in string, delimiter string) (out []string)
- func StringSlice(slice any, from int, to int) []string
- func Stringify(in any) []string
- func TrimSpace(in any) []string
- func Unique(in any) []any
- func UniqueStrings(in any) []string
- type CompareFunc
- type IterationFunc
- type MapFunc
- type MapStringFunc
Constants ¶
This section is empty.
Variables ¶
var RelaxedEqualityCompare = func(_ int, first any, second any) bool { if v, err := stringutil.RelaxedEqual(first, second); err == nil && v == true { return true } return false }
var Stop = utils.Stop
Functions ¶
func Append ¶ added in v1.5.53
Returns a copy of the given slicified value with the given additional values appended.
func At ¶
Returns the element in the given indexable value at the given index. If the index is present, the second return value will be true. If the index is not present, or the given input is not indexable, the second return value will be false.
func Autotype ¶
Returns a copy of the given slice with each element's value passed to stringutil.Autotype
func Compact ¶
Removes all elements from the given interface slice that are "empty", which is defined as being nil, a nil or zero-length array, chan, map, slice, or string.
The zero values of any other type are not considered empty and will remain in the return value.
func CompactString ¶
Removes all zero-length strings from the given string slice, returning a new slice with the values removed.
func Contains ¶
func Contains(in any, value any, comparators ...CompareFunc) bool
Return whether the given slice contains the given value. If a comparator is provided, it will be used to compare the elements.
func ContainsAllStrings ¶
Returns whether the given string slice contains all of the following strings.
func ContainsAnyString ¶
Returns whether the given string slice contains any of the following strings.
func ContainsString ¶
Returns whether the given string slice contains a given string.
func Difference ¶ added in v1.7.51
Return the slice that results from removing elements in second from the first.
func Each ¶
func Each(slice any, iterFn IterationFunc) error
Iterate through each element of the given array or slice, calling iterFn exactly once for each element. Otherwise, call iterFn one time with the given input as the argument.
func FirstNonZero ¶ added in v1.9.8
Returns the first element in the given inputs that is not that type's zero value. All input values are flattened into a single array, so variadic elements can contain scalar or array values.
func IntersectStrings ¶
Return the intersection of two string slices.
func MapString ¶
func MapString(in any, fn MapStringFunc) []string
Returns a copy of the given slice with each element modified by the a given function, then converted to a string.
func Slice ¶ added in v1.6.30
Returns a new slice with only the specified subset of items included. In addition to the normal slice index rules in Golang, negative indices are also supported. If a negative index is given for the from and/or to values, the index will be treated as being relative to the end of the given slice. For example:
Slice([]any{1,2,3,4,5}, -5, -1) // returns []any{1, 2, 3, 4, 5} Slice([]any{1,2,3,4,5}, -2, -1) // returns []any{4, 5} Slice([]any{1,2,3,4,5}, -1, -1) // returns []any{5} Slice([]any{1,2,3,4,5}, -4, -2) // returns []any{2, 3, 4}
func SplitCompact ¶ added in v1.12.3
Splits the given string by a delimiter, then eliminates any zero-length items.
func SplitTrimSpaceCompact ¶ added in v1.12.3
Splits the given string by a delimiter, trims the space around each item, then eliminates any zero-length results.
func StringSlice ¶ added in v1.6.30
Same as slice, but returns strings.
func Stringify ¶
Converts all elements of the given interface slice to strings using the "%v" format string via the fmt package.
func UniqueStrings ¶
Returns a new slice with only unique string elements from the given interface included.
Types ¶
type IterationFunc ¶
type IterationFunc = utils.IterationFunc