closures

作者: BANGBANGNT | 来源:发表于2017-12-07 19:21 被阅读0次
    package main
    
    import "fmt"
    
    func intSeq() func() int {
        i := 0
        return func() int {
            i += 1
            return i
        }
    }
    
    func main() {
        nextInt := intSeq()
        fmt.Println(nextInt())
        fmt.Println(nextInt())
        fmt.Println(nextInt())
        newInts := intSeq()
        fmt.Println(newInts())
    }
    
    

    相关文章

      网友评论

          本文标题:closures

          本文链接:https://www.haomeiwen.com/subject/zpujixtx.html