- added FindFirst and FindLast
- removed Search
This commit is contained in:
parent
0592add8ca
commit
26ea846e93
19
filter.go
19
filter.go
@ -9,3 +9,22 @@ func Filter[T any](slice []T, f func(T) bool) []T {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func FindFirst[T any](slice []T, f func(T) bool) (T, bool) {
|
||||
for _, v := range slice {
|
||||
if f(v) {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
return *new(T), false
|
||||
}
|
||||
|
||||
func FindLast[T any](slice []T, f func(T) bool) (T, bool) {
|
||||
for i := len(slice); i >= 0; i-- {
|
||||
v := slice[i]
|
||||
if f(v) {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
return *new(T), false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user