Programming Code Center(PCC)
[GO]

(PCC)::[How-to-use-function-intSeq-returns-another-function-in-go-language]::[go]

File Name : closures.go

package main

import "fmt"

func intSeq() func() int {
    i := 0
    return func() int {
        i++
        return i
    }
}

func main() {

    nextInt := intSeq()

    fmt.Println(nextInt())
    fmt.Println(nextInt())
    fmt.Println(nextInt())

    newInts := intSeq()
    fmt.Println(newInts())
}

Output :

closures.jpg