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

Some: allocate slice to keep track unused indexes is not necessary

Waste of memory for those unused indexes. It got replaced by a simple
boolean to keep track of it.
This commit is contained in:
Marcel Edmund Franke
2021-12-25 12:55:09 +01:00
parent 3045d56503
commit 578b1bba65

View File

@@ -122,15 +122,15 @@ func Some(slice, function interface{}) bool {
panic("Filter function must be of type func(int, " + elemType.String() + ")" + reflect.ValueOf(true).Type().String())
}
var indexes []int
has := false
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)
has = true
}
}
return len(indexes) > 0
return has
}
// Filter iterates over elements of slice, returning an slice of all elements `signature` returns truthy for.