Filter returns all elements that satisfy the condition.
(haystack []T, cond func(T) bool)
| 111 | |
| 112 | // Filter returns all elements that satisfy the condition. |
| 113 | func Filter[T any](haystack []T, cond func(T) bool) []T { |
| 114 | out := make([]T, 0, len(haystack)) |
| 115 | for _, hay := range haystack { |
| 116 | if cond(hay) { |
| 117 | out = append(out, hay) |
| 118 | } |
| 119 | } |
| 120 | return out |
| 121 | } |
| 122 | |
| 123 | // Overlap returns if the 2 sets have any overlap (element(s) in common) |
| 124 | func Overlap[T comparable](a []T, b []T) bool { |
no outgoing calls