github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/durgaform/marks.go (about) 1 package durgaform 2 3 import ( 4 "fmt" 5 "sort" 6 7 "github.com/zclconf/go-cty/cty" 8 ) 9 10 // marksEqual compares 2 unordered sets of PathValue marks for equality, with 11 // the comparison using the cty.PathValueMarks.Equal method. 12 func marksEqual(a, b []cty.PathValueMarks) bool { 13 if len(a) == 0 && len(b) == 0 { 14 return true 15 } 16 17 if len(a) != len(b) { 18 return false 19 } 20 21 less := func(s []cty.PathValueMarks) func(i, j int) bool { 22 return func(i, j int) bool { 23 // the sort only needs to be consistent, so use the GoString format 24 // to get a comparable value 25 return fmt.Sprintf("%#v", s[i]) < fmt.Sprintf("%#v", s[j]) 26 } 27 } 28 29 sort.Slice(a, less(a)) 30 sort.Slice(b, less(b)) 31 32 for i := 0; i < len(a); i++ { 33 if !a[i].Equal(b[i]) { 34 return false 35 } 36 } 37 38 return true 39 }