Created
February 21, 2017 02:43
-
-
Save ken39arg/56f02f8ec3ccb89de6dfbfba2f240dff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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