GO語言"container/ring"包中"Ring.Do"類型的用法及代碼示例。
用法:
func(r *Ring) Do(f func(any))
Do 以前向順序在環的每個元素上調用函數 f。如果 f 改變 *r,Do 的行為是不確定的。
例子:
package main
import (
"container/ring"
"fmt"
)
func main() {
// Create a new ring of size 5
r := ring.New(5)
// Get the length of the ring
n := r.Len()
// Initialize the ring with some integer values
for i := 0; i < n; i++ {
r.Value = i
r = r.Next()
}
// Iterate through the ring and print its contents
r.Do(func(p any) {
fmt.Println(p.(int))
})
}
輸出:
0 1 2 3 4
相關用法
- GO Ring.Unlink用法及代碼示例
- GO Ring.Move用法及代碼示例
- GO Ring.Len用法及代碼示例
- GO Ring.Prev用法及代碼示例
- GO Ring.Next用法及代碼示例
- GO Ring.Link用法及代碼示例
- GO Regexp.FindString用法及代碼示例
- GO Regexp.FindAllIndex用法及代碼示例
- GO ResponseRecorder用法及代碼示例
- GO ReverseBytes64用法及代碼示例
- GO ReverseBytes16用法及代碼示例
- GO Regexp.ReplaceAllLiteralString用法及代碼示例
- GO Regexp.FindStringSubmatch用法及代碼示例
- GO Rows用法及代碼示例
- GO Regexp.FindAllString用法及代碼示例
- GO ReadMessage用法及代碼示例
- GO Regexp.ExpandString用法及代碼示例
- GO ResponseWriter用法及代碼示例
- GO Regexp.FindAllStringSubmatch用法及代碼示例
- GO Reverse用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Ring.Do。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。