Add FindIndexed

This commit is contained in:
世界 2023-06-13 22:06:01 +08:00
parent 2812461739
commit 00f3153336
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -130,6 +130,15 @@ func Find[T any](arr []T, block func(it T) bool) T {
return DefaultValue[T]()
}
func FindIndexed[T any](arr []T, block func(index int, it T) bool) T {
for i, it := range arr {
if block(i, it) {
return it
}
}
return DefaultValue[T]()
}
//go:norace
func Dup[T any](obj T) T {
if UnsafeBuffer {