Golang container/ring.Ring.Do() function example

package container/ring

Do calls function f (1st parameter) on each element of the ring, in forward order. The behavior of Do is undefined if f changes *r. (see http://golang.org/pkg/container/ring/#Ring.Do)

Golang container/ring.Ring.Do() function usage example

 package main

 import (
 "container/ring"
 "fmt"
 )

 func main() {
 r := ring.New(10)

 i := 0
 f := func(v interface{}) {
 v = i
 i++
 fmt.Printf("%d\n", v)
 }


 r.Do(f)
 }

Output :

0

1

2

3

4

5

6

7

8

9

Reference :

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

Advertisement