Skip to content

Instantly share code, notes, and snippets.

@michaljemala
Created September 6, 2019 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaljemala/6059f1937dde8e308e4fd364baa2ee98 to your computer and use it in GitHub Desktop.
Save michaljemala/6059f1937dde8e308e4fd364baa2ee98 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"hova.dzia.poliev.ka/slice"
)
func main() {
x := slice.Unordered{1, 2, 3}
y := slice.Unordered{3, 2, 1}
fmt.Println(slice.Equal(x, y))
fmt.Println(slice.Match(x, y))
}
-- go.mod --
module hova.dzia.poliev.ka
-- slice/slice.go --
package slice
import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)
type Unordered []interface{}
func Equal(x, y interface{}) bool {
return cmp.Equal(x, y)
}
func Match(x, y interface{}) bool {
return cmp.Equal(x, y, cmp.Comparer(func(x, y Unordered) bool {
return assert.ElementsMatch(nil, x, y)
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment