SHARE
TWEET

Untitled

a guest Sep 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.  
  6.     "hova.dzia.poliev.ka/slice"
  7. )
  8.  
  9. func main() {
  10.     x := slice.Unordered{1, 2, 3}
  11.     y := slice.Unordered{3, 2, 1}
  12.     fmt.Println(slice.Equal(x, y))
  13.     fmt.Println(slice.Match(x, y))
  14.  
  15. }
  16. -- go.mod --
  17. module hova.dzia.poliev.ka
  18. -- slice/slice.go --
  19. package slice
  20.  
  21. import (
  22.     "github.com/google/go-cmp/cmp"
  23.     "github.com/stretchr/testify/assert"
  24. )
  25.  
  26. type Unordered []interface{}
  27.  
  28. func Equal(x, y interface{}) bool {
  29.     return cmp.Equal(x, y)
  30. }
  31.  
  32. func Match(x, y interface{}) bool {
  33.     return cmp.Equal(x, y, cmp.Comparer(func(x, y Unordered) bool {
  34.         return assert.ElementsMatch(nil, x, y)
  35.     }))
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top