Documentation ¶
Overview ¶
Package sliceutil provides methods for working with slices
Index ¶
- func Contains(slice []string, value string) bool
- func Copy(slice []string) []string
- func CopyFloats(slice []float64) []float64
- func CopyInts(slice []int) []int
- func Deduplicate(slice []string) []string
- func ErrorToString(data []error) []string
- func Exclude(slice []string, items ...string) []string
- func Index(slice []string, item string) int
- func IntToInterface(data []int) []interface{}
- func StringToError(data []string) []error
- func StringToInterface(data []string) []interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy creates copy of given slice
Example ¶
s1 := []string{"A", "B", "C"} s2 := Copy(s1) fmt.Printf("%v", s2)
Output: [A B C]
func CopyFloats ¶
CopyFloats creates copy of given slice
Example ¶
s1 := []float64{1.0, 5.0} s2 := CopyFloats(s1) fmt.Printf("%v", s2)
Output: [1 5]
func CopyInts ¶
CopyInts creates copy of given slice
Example ¶
s1 := []int{1, 2, 3} s2 := CopyInts(s1) fmt.Printf("%v", s2)
Output: [1 2 3]
func Deduplicate ¶
Deduplicate removes duplicates from slice. Slice must be sorted before deduplication.
Example ¶
s := []string{"A", "A", "A", "B", "C", "C", "D"} fmt.Println(Deduplicate(s))
Output: [A B C D]
func ErrorToString ¶
ErrorToString converts slice with errors to slice with strings
Example ¶
s := []error{fmt.Errorf("error1")} fmt.Printf("%v", ErrorToString(s))
Output: [error1]
func Exclude ¶
Exclude removes items from slice
Example ¶
s := []string{"A", "B", "C", "D"} fmt.Println(Exclude(s, "B", "D"))
Output: [A C]
func Index ¶
Index returns index of given item in a slice or -1 otherwise
Example ¶
s := []string{"A", "B", "C"} fmt.Println(Index(s, "C")) fmt.Println(Index(s, "D"))
Output: 2 -1
func IntToInterface ¶
func IntToInterface(data []int) []interface{}
IntToInterface converts slice with ints to slice with interface{}
Example ¶
s := []int{1, 2} fmt.Printf("%v", IntToInterface(s))
Output: [1 2]
func StringToError ¶
StringToError converts slice with strings to slice with errors
func StringToInterface ¶
func StringToInterface(data []string) []interface{}
StringToInterface converts slice with strings to slice with interface{}
Example ¶
s := []string{"A", "B"} fmt.Printf("%v", StringToInterface(s))
Output: [A B]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.