Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains(slice, val interface{}) bool
Contains determines if the slice contains val.
Example ¶
package main import ( "fmt" "github.com/hamba/slices" ) func main() { slice := []string{"foo", "bar"} v := "bar" fmt.Println(slices.Contains(slice, v)) }
Output: true
func Except ¶
func Except(slice, other interface{}) interface{}
Except returns a slice with the elements of slice that are not in other. When the slices different, slice is returned.
Example ¶
package main import ( "fmt" "github.com/hamba/slices" ) func main() { slice := []string{"foo", "bar", "baz", "bat"} other := []string{"bar", "baz", "test"} fmt.Println(slices.Except(slice, other)) // Outputs: [foo bat] }
Output:
func GreaterOf ¶
GreaterOf returns a greater function for slice sorting.
Example ¶
package main import ( "fmt" "sort" "github.com/hamba/slices" ) func main() { slice := []string{"foo", "bar", "baz"} sort.Slice(slice, slices.GreaterOf(slice)) fmt.Println(slice) // Outputs: [bar baz foo] }
Output:
func Intersect ¶
func Intersect(slice, other interface{}) interface{}
Intersection returns a slice with the intersection of slice and other. When the slices are the same, slice is returned.
Example ¶
package main import ( "fmt" "github.com/hamba/slices" ) func main() { slice := []string{"foo", "bar", "baz", "bat"} other := []string{"bar", "baz", "test"} fmt.Println(slices.Intersect(slice, other)) // Outputs: [bar baz] }
Output:
Types ¶
This section is empty.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.