python在go中枚举
假设我有斐波那契数的生成器,我想使用enumerate(get_next_fibs(10))并且我想有对生成器index, number_from_generator,我正在努力寻找“命名返回值”的解决方案这不是应该如何完成,而是为了学习有关生成器的特定内容package mainimport "fmt"func get_next_fibs(ii int) func() int { i := 0 a, b := 0, 1 fc := func() int { i++ a, b = b, a+b if ii <= i { return -1 } return a } return fc}func enumerate(iter func() int) func() (index, v int) { index := 0 fc := func() (index, v int) { v := iter() return index++ } return fc}func main() { iter := enumerate(get_next_fibs(10)) // iter := get_next_fibs(10) fmt.Printf("iter = %T\n", iter) for tuple := iter(); tuple != -1; tuple = iter() { fmt.Println("tuple:", tuple) }}