container/ring

Guided tour · Containers · pkg.go.dev →

Circular linked list. Fixed-size ring buffer where advancing past the end loops to the front. Rarely needed.

Create and walk

Initialize a ring of 5 and walk it

r := ring.New(5)
for i := 0; i < r.Len(); i++ {
    r.Value = i
    r = r.Next()
}
r.Do(func(x any) { fmt.Println(x) })