MCPcopy Index your code
hub / github.com/coder/coder / CountConsecutive

Function CountConsecutive

coderd/util/slice/slice.go:224–238  ·  view source on GitHub ↗
(needle T, haystack ...T)

Source from the content-addressed store, hash-verified

222}
223
224func 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.
241func Convert[F any, T any](a []F, f func(F) T) []T {

Callers 1

NextStateFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected