Find returns the first element that satisfies the condition.
(haystack []T, cond func(T) bool)
| 100 | |
| 101 | // Find returns the first element that satisfies the condition. |
| 102 | func Find[T any](haystack []T, cond func(T) bool) (T, bool) { |
| 103 | for _, hay := range haystack { |
| 104 | if cond(hay) { |
| 105 | return hay, true |
| 106 | } |
| 107 | } |
| 108 | var empty T |
| 109 | return empty, false |
| 110 | } |
| 111 | |
| 112 | // Filter returns all elements that satisfy the condition. |
| 113 | func Filter[T any](haystack []T, cond func(T) bool) []T { |
no outgoing calls