Documentation
¶
Overview ¶
Package sliceutil provides functions for working with slices.
The "set" helpers are simple implementations, and don't operate on true "sets" (e.g. it will retain order, []int64 can contain duplicates). Consider using something like golang-set if you want to use sets and care a lot about performance: https://github.com/deckarep/golang-set
Index ¶
- func ChooseString(l []string) string
- func ComplementInt(a, b []int64) (aOnly, bOnly []int64)
- func DifferenceInt(set []int64, others ...[]int64) []int64
- func DifferenceString(set []string, others ...[]string) []string
- func FilterInt(list []int64, fun func(int64) bool) []int64
- func FilterIntEmpty(e int64) bool
- func FilterString(list []string, fun func(string) bool) []string
- func FilterStringEmpty(e string) bool
- func InInt64Slice(list []int64, i int64) bool
- func InIntSlice(list []int, i int) bool
- func InStringSlice(list []string, str string) bool
- func JoinFloat(nums []float64) string
- func JoinInt(ints []int64) string
- func Range(start, end int) []int
- func RepeatString(s string, n int) (r []string)
- func SplitFloat(s string) ([]float64, error)
- func SplitInt(s string) ([]int64, error)
- func UniqInt64(list []int64) []int64
- func UniqString(list []string) []string
- func UniqueMergeSlices(s [][]int64) (result []int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChooseString ¶
ChooseString chooses a random item from the list.
func ComplementInt ¶
ComplementInt returns the complement of the two lists; that is, the first return value will contain elements that are only in "a" (and not in "b"), and the second return value will contain elements that are only in "b" (and not in "a").
func DifferenceInt ¶
DifferenceInt returns a new slice with elements that are in "set" but not in "others".
func DifferenceString ¶
DifferenceString returns a new slice with elements that are in "set" but not in "others".
func FilterInt ¶
FilterInt filters a list. The function will be called for every item and those that return false will not be included in the return value.
func FilterIntEmpty ¶
FilterIntEmpty can be used as an argument for FilterInt() and will return false if e is empty or contains only whitespace.
func FilterString ¶
FilterString filters a list. The function will be called for every item and those that return false will not be included in the return value.
func FilterStringEmpty ¶
FilterStringEmpty can be used as an argument for FilterString() and will return false if e is empty or contains only whitespace.
func InInt64Slice ¶
InInt64Slice reports whether i is within list
func InIntSlice ¶
InIntSlice reports whether i is within list
func InStringSlice ¶
InStringSlice reports whether str is within list
func JoinFloat ¶
JoinFloat converts a slice of floats to a comma separated string. Useful for inserting into a query without the option of parameterization.
func JoinInt ¶
JoinInt converts a slice of ints to a comma separated string. Useful for inserting into a query without the option of parameterization.
func RepeatString ¶
RepeatString returns a slice with the string s repeated n times.
func SplitFloat ¶ added in v1.3.1
SplitFloat converts a string of integers to a slice of float64.
func UniqInt64 ¶
UniqInt64 removes duplicate entries from list. The list does not have to be sorted.
func UniqString ¶
UniqString removes duplicate entries from list.
func UniqueMergeSlices ¶
UniqueMergeSlices takes a slice of slices of int64s and returns an unsorted slice of unique int64s.
Types ¶
This section is empty.