遍历函数?Go 1.22 中隐藏的功能

鸟窝 at 
遍历函数?Go 1.22中隐藏的功能的配图
Go 1.22 中可以 range 一个整数,比如下面的代码:123for i := range 10 { fmt.Println(i)}这个大家都已经知道了,其实对应的提案中还有一个隐藏的功能,就是可以 range 一个函数,比如下面的代码(摘自官方代码库 internal/trace/v2/event.go):12345678910111213141516171819// Frames is an iterator over the frames in a Stack.func (s Stack) Frames(yield func(f StackFrame) bool) bool ……