1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

Every: use int counter (#6)

Use counter to verify all elements passed the perdicate func.
Replace slice of indexes with int counter.
This commit is contained in:
donutloop
2021-12-29 02:51:50 +01:00
committed by GitHub
parent 8b1171d0cb
commit b106c428ae

View File

@@ -100,15 +100,15 @@ func Every(slice, function interface{}) bool {
panic("function param should be of type func(int, " + elemType.String() + ")" + reflect.ValueOf(true).Type().String())
}
var indexes []int
var currentLength int
for i := 0; i < sv.Len(); i++ {
flag := fn.Call([]reflect.Value{reflect.ValueOf(i), sv.Index(i)})[0]
if flag.Bool() {
indexes = append(indexes, i)
currentLength++
}
}
return len(indexes) == sv.Len()
return currentLength == sv.Len()
}
// Some return true if any of the values in the list pass the predicate function.