Golang container/ring.Ring.Next function example

package container/ring

Next returns the next ring element. The ring that is going to be "next"ed must not be empty.

Golang container/ring.Ring.Next function usage

 package main

 import (
 "container/ring"
 "fmt"
 )

 func main() {

  r := ring.New(10)

  // populate our ring
  for i := 0; i < 10; i++ {
 r.Value = i
 r = r.Next() // Next element to populate
  }

  f := func(v interface{}) {
 fmt.Printf("%d ", v)
 }

  fmt.Println("Values in ring ")
  r.Do(f)
  fmt.Println()

 }

Output :

Values in ring

0 1 2 3 4 5 6 7 8 9

Reference :

http://golang.org/pkg/container/ring/#Ring.Next

Advertisement