package sliceutil
import "github.com/teamwork/utils/sliceutil"
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 CSVtoInt64Slice(csv string) ([]int64, error)
- func ChooseString(l []string) string
- func Complement(a, b []int64) (aOnly, bOnly []int64)
- func Difference(set []int64, others ...[]int64) []int64
- 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 InFoldedStringSlice(list []string, str string) bool
- func InInt64Slice(list []int64, i int64) bool
- func InIntSlice(list []int, i int) bool
- func InStringSlice(list []string, str string) bool
- func InterfaceSliceTo(src []interface{}, dst interface{}) interface{}
- func Intersection(a, b []int64) []int64
- func JoinInt(ints []int64) string
- func Range(start, end int) []int
- func RemoveString(list []string, s string) (out []string)
- func RepeatString(s string, n int) (r []string)
- func StringMap(list []string, f func(string) string) []string
- func UniqInt64(list []int64) []int64
- func UniqString(list []string) []string
- func UniqueMergeSlices(s [][]int64) (result []int64)
Functions ¶
func CSVtoInt64Slice ¶
CSVtoInt64Slice converts a string of integers to a slice of int64.
func ChooseString ¶
ChooseString chooses a random item from the list.
func Complement ¶
Complement 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 Difference ¶
Difference 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 InFoldedStringSlice ¶
InFoldedStringSlice reports whether str is within list(case-insensitive)
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(case-sensitive)
func InterfaceSliceTo ¶
func InterfaceSliceTo(src []interface{}, dst interface{}) interface{}
InterfaceSliceTo converts []interface to any given slice. It will ~optimistically~ try to convert interface item to the dst item type
func Intersection ¶
Intersection returns the elements common to both a and b
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 Range ¶
Range creates an []int counting at "start" up to (and including) "end".
func RemoveString ¶
RemoveString removes any occurrence of a string from a slice.
func RepeatString ¶
RepeatString returns a slice with the string s reated n times.
func StringMap ¶
StringMap returns a list strings where each item in list has been modified by f
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.
Source Files ¶
- Version
- v1.0.0 (latest)
- Published
- Mar 14, 2022
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 20 hours ago –
Tools for package owners.