Skip to content

Instantly share code, notes, and snippets.

@ken39arg
Created February 21, 2017 02:32
Show Gist options
  • Select an option

  • Save ken39arg/9c7f45efaf4a190b4d4cdc4795fcdcf1 to your computer and use it in GitHub Desktop.

Select an option

Save ken39arg/9c7f45efaf4a190b4d4cdc4795fcdcf1 to your computer and use it in GitHub Desktop.
package test
import "reflect"
func SliceEqualBy(slice interface{}, checkFun func(i int) bool) bool {
rv := reflect.ValueOf(slice)
for i := 0; i < rv.Len(); i++ {
if !checkFun(i) {
return false
}
}
return true
}
@ken39arg

ken39arg commented Feb 21, 2017

Copy link
Copy Markdown
Author
if !test.SliceEqualBy(foo, func(i int) bool { return foo[i].BarId == bar[i].ID }) {
    t.Error("not equal")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment