github.com/hamba/slices@v0.2.1-0.20220316050741-75c057d92699/example_test.go (about) 1 package slices_test 2 3 import ( 4 "fmt" 5 "sort" 6 7 "github.com/hamba/slices" 8 ) 9 10 func ExampleContains() { 11 slice := []string{"foo", "bar"} 12 v := "bar" 13 14 fmt.Println(slices.Contains(slice, v)) 15 // Output: true 16 } 17 18 func ExampleGreaterOf() { 19 slice := []string{"foo", "bar", "baz"} 20 sort.Slice(slice, slices.GreaterOf(slice)) 21 22 fmt.Println(slice) 23 // Outputs: [bar baz foo] 24 } 25 26 func ExampleLesserOf() { 27 slice := []string{"foo", "bar", "baz"} 28 sort.Slice(slice, slices.LesserOf(slice)) 29 30 fmt.Println(slice) 31 // Outputs: [foo baz bar] 32 } 33 34 func ExampleIntersect() { 35 slice := []string{"foo", "bar", "baz", "bat"} 36 other := []string{"bar", "baz", "test"} 37 38 fmt.Println(slices.Intersect(slice, other)) 39 // Outputs: [bar baz] 40 } 41 42 func ExampleExcept() { 43 slice := []string{"foo", "bar", "baz", "bat"} 44 other := []string{"bar", "baz", "test"} 45 46 fmt.Println(slices.Except(slice, other)) 47 // Outputs: [foo bat] 48 }