diff --git a/go/02-next-level/04-closure.go b/go/02-next-level/04-closure.go new file mode 100644 index 0000000..f057a03 --- /dev/null +++ b/go/02-next-level/04-closure.go @@ -0,0 +1,23 @@ +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()) +}