Skip to content

Instantly share code, notes, and snippets.

@ken39arg
Created February 21, 2017 02:43
Show Gist options
  • Save ken39arg/56f02f8ec3ccb89de6dfbfba2f240dff to your computer and use it in GitHub Desktop.
Save ken39arg/56f02f8ec3ccb89de6dfbfba2f240dff 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
}
func SliceMap(slice interface{}, fun func(i int) interface{}) []interface{} {
rv := reflect.ValueOf(slice)
n := rv.Len()
ret := make([]interface{}, n)
for i := 0; i < n; i++ {
ret[i] = fun(i)
}
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment