add SliceIndex func

This commit is contained in:
Jay 2019-01-16 15:05:16 +08:00
parent b1a8bce041
commit b266ebeb2d

View File

@ -169,3 +169,13 @@ func CheckExists(filePath string, allowDir bool) bool {
}
return true
}
// SliceIndex -
func SliceIndex(limit int, predicate func(idx int) bool) int {
for i := 0; i < limit; i++ {
if predicate(i) {
return i
}
}
return -1
}