lotus/lib/harmony/tasks/common.go
2023-10-06 11:46:13 -05:00

16 lines
234 B
Go

package tasks
func SliceIfFound[T any](slice []T, f func(T) bool) []T {
ct := 0
for i, v := range slice {
if f(v) {
slice[ct], slice[i] = slice[i], slice[ct]
ct++
}
}
if ct == 0 {
return slice
}
return slice[:ct]
}