Documentation ¶
Overview ¶
Utilities for converting, manipulating, and iterating over slices
Index ¶
- Variables
- func Append(in interface{}, values ...interface{}) []interface{}
- func At(in interface{}, index int) (interface{}, bool)
- func Autotype(in interface{}) []interface{}
- func Chunks(in interface{}, size int) [][]interface{}
- func Compact(in interface{}) []interface{}
- func CompactString(in []string) []string
- func Contains(in interface{}, value interface{}, 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 interface{}, second interface{}) []interface{}
- func Each(slice interface{}, iterFn IterationFunc) error
- func First(in interface{}) interface{}
- func FirstNonZero(inputs ...interface{}) interface{}
- func Flatten(in interface{}) []interface{}
- func Get(in interface{}, index int) interface{}
- func Intersect(a interface{}, b interface{}) []interface{}
- func IntersectStrings(a []string, b []string) []string
- func Last(in interface{}) interface{}
- func Len(in interface{}) int
- func Map(in interface{}, fn MapFunc) []interface{}
- func MapString(in interface{}, fn MapStringFunc) []string
- func Or(in ...interface{}) interface{}
- func OrString(in ...string) string
- func Rest(in interface{}) []interface{}
- func Slice(slice interface{}, from int, to int) []interface{}
- func Sliceify(in interface{}) []interface{}
- func StringSlice(slice interface{}, from int, to int) []string
- func Stringify(in interface{}) []string
- func TrimSpace(in interface{}) []string
- func Unique(in interface{}) []interface{}
- func UniqueStrings(in interface{}) []string
- type CompareFunc
- type IterationFunc
- type MapFunc
- type MapStringFunc
Constants ¶
This section is empty.
Variables ¶
var RelaxedEqualityCompare = func(_ int, first interface{}, second interface{}) bool { if v, err := stringutil.RelaxedEqual(first, second); err == nil && v == true { return true } return false }
var Stop = utils.Stop
var StrictEqualityCompare = func(_ int, first interface{}, second interface{}) bool { if first == second { return true } return false }
Functions ¶
func Append ¶ added in v1.5.53
func Append(in interface{}, values ...interface{}) []interface{}
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 ¶
func Autotype(in interface{}) []interface{}
Returns a copy of the given slice with each element's value passed to stringutil.Autotype
func Chunks ¶
func Chunks(in interface{}, size int) [][]interface{}
Divide the given slice into chunks of (at most) a given length
func Compact ¶
func Compact(in interface{}) []interface{}
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 interface{}, value interface{}, 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
func Difference(first interface{}, second interface{}) []interface{}
Return the slice that results from removing elements in second from the first.
func Each ¶
func Each(slice interface{}, 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 First ¶
func First(in interface{}) interface{}
Returns the first element from the given slice, array or string; or nil.
func FirstNonZero ¶ added in v1.9.8
func FirstNonZero(inputs ...interface{}) interface{}
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 Flatten ¶
func Flatten(in interface{}) []interface{}
Returns the given slice as a single-level flattened array.
func Get ¶
func Get(in interface{}, index int) interface{}
Returns the nth element from the given slice, array or string; or nil.
func Intersect ¶
func Intersect(a interface{}, b interface{}) []interface{}
Return the intersection of two slices.
func IntersectStrings ¶
Return the intersection of two string slices.
func Last ¶
func Last(in interface{}) interface{}
Returns the last element from the given slice, array or string; or nil.
func Map ¶
func Map(in interface{}, fn MapFunc) []interface{}
Returns a copy of the given slice with each element modified by the a given function.
func MapString ¶
func MapString(in interface{}, 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 Or ¶
func Or(in ...interface{}) interface{}
Returns the first item that is not the zero value for that value's type.
func Rest ¶
func Rest(in interface{}) []interface{}
Returns the all but the first element from the given slice, array or string; or nil.
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([]interface{}{1,2,3,4,5}, -5, -1) // returns []interface{}{1, 2, 3, 4, 5} Slice([]interface{}{1,2,3,4,5}, -2, -1) // returns []interface{}{4, 5} Slice([]interface{}{1,2,3,4,5}, -1, -1) // returns []interface{}{5} Slice([]interface{}{1,2,3,4,5}, -4, -2) // returns []interface{}{2, 3, 4}
func Sliceify ¶
func Sliceify(in interface{}) []interface{}
Takes some input value and returns it as a slice.
func StringSlice ¶ added in v1.6.30
Same as slice, but returns strings.
func Stringify ¶
func Stringify(in interface{}) []string
Converts all elements of the given interface slice to strings using the "%v" format string via the fmt package.
func TrimSpace ¶ added in v1.7.13
func TrimSpace(in interface{}) []string
Trims the whitespace from each element in the given array.
func Unique ¶
func Unique(in interface{}) []interface{}
Returns a new slice with only unique elements from the given interface included.
func UniqueStrings ¶
func UniqueStrings(in interface{}) []string
Returns a new slice with only unique string elements from the given interface included.
Types ¶
type CompareFunc ¶
type IterationFunc ¶
type IterationFunc = utils.IterationFunc