(needle T, haystack ...T)
| 222 | } |
| 223 | |
| 224 | func CountConsecutive[T comparable](needle T, haystack ...T) int { |
| 225 | maxLength := 0 |
| 226 | curLength := 0 |
| 227 | |
| 228 | for _, v := range haystack { |
| 229 | if v == needle { |
| 230 | curLength++ |
| 231 | } else { |
| 232 | maxLength = max(maxLength, curLength) |
| 233 | curLength = 0 |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return max(maxLength, curLength) |
| 238 | } |
| 239 | |
| 240 | // Convert converts a slice of type F to a slice of type T using the provided function f. |
| 241 | func Convert[F any, T any](a []F, f func(F) T) []T { |