MCPcopy Create free account
hub / github.com/GopherML/bag / ForEach

Method ForEach

circularbuffer.go:48–69  ·  view source on GitHub ↗

ForEach will iterate through the buffer items

(fn func(t T) (end bool))

Source from the content-addressed store, hash-verified

46
47// ForEach will iterate through the buffer items
48func (c *circularBuffer[T]) ForEach(fn func(t T) (end bool)) (ended bool) {
49 // First index is at starting position
50 index := c.start
51 // Iterate for the length of the buffer
52 for i := 0; i < c.len; i++ {
53 // Get item at current index
54 item := c.s[index]
55 // Pass item to func
56 if fn(item) {
57 // Func returned break boolean as true, return true
58 return true
59 }
60
61 // Increment index and see if index exceeds length
62 if index++; index >= c.len {
63 // Index exceeds length, set to 0
64 index = 0
65 }
66 }
67
68 return
69}
70
71// Len will return the length of a circular buffer
72func (c *circularBuffer[T]) Len() int {

Callers 4

StringMethod · 0.80
toWordsFunction · 0.80
StringMethod · 0.80

Calls

no outgoing calls

Tested by 1