Documentation
¶
Overview ¶
Package slice provides some assistant functions about slice.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[E comparable](vs []E, v E) bool
Contains reports whether vs contains v.
Example ¶
fmt.Println(Contains([]int{1, 2, 3}, 0)) fmt.Println(Contains([]int{1, 2, 3}, 1)) fmt.Println(Contains([]int{1, 2, 3}, 2)) fmt.Println(Contains([]int{1, 2, 3}, 3)) fmt.Println(Contains([]int{1, 2, 3}, 4))
Output: false true true true false
func Reverse ¶
func Reverse[E any](vs []E)
Reverse reverses the elements in the slice.
Example ¶
vs1 := []string{"a", "b", "c", "d"} Reverse(vs1) fmt.Println(vs1) vs2 := []int{1, 2, 3, 4} Reverse(vs2) fmt.Println(vs2)
Output: [d c b a] [4 3 2 1]
func ToInterfaces ¶
func ToInterfaces[T any](vs []T) []interface{}
ToInterfaces converts []any to []interface{}.
Example ¶
ss := []string{"a", "b", "c"} vs1 := ToInterfaces(ss) fmt.Printf("%T: %v\n", vs1, vs1) ints := []int{1, 2, 3} vs2 := ToInterfaces(ints) fmt.Printf("%T: %v\n", vs2, vs2)
Output: []interface {}: [a b c] []interface {}: [1 2 3]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.