FindOneInSlice 추가

This commit is contained in:
2023-12-02 01:25:12 +09:00
parent 51a1e352bc
commit 0182ea7b01
3 changed files with 55 additions and 12 deletions

View File

@ -115,3 +115,12 @@ func ShrinkSlice[T any](in []T, compare func(elem T) bool) []T {
}
return in[:cursor]
}
func FindOneInSlice[T any](in []T, compare func(elem *T) bool) (int, *T) {
for i, e := range in {
if compare(&e) {
return i, &e
}
}
return -1, nil
}