我有以下 Go 代碼段。我有一片package mainimport "fmt"func main() { y := []int{0, 1, 1, 2, 3, 5, 8} return y}func toParseY(int y) { for i, v := range y { fmt.Println(i, v) }}我知道我必須將切片作為參數(shù)傳遞給 toParseY 函數(shù),但是當(dāng)我嘗試它時(shí),我得到了這個(gè)錯(cuò)誤(編譯器甚至沒(méi)有得到# command-line-arguments./ude.go:8:2: too many arguments to return have ([]int) want ()./ude.go:11:19: undefined: y./ude.go:12:20: undefined: y在 Go 中實(shí)現(xiàn)它的正確方法是什么?
如何從其他函數(shù)解析切片
函數(shù)式編程
2022-05-05 16:08:19