Go 클로저

Jmnote (토론 | 기여)님의 2021년 10월 20일 (수) 13:15 판 (새 문서: ==개요== ;Go closure ;Go 클로저 <syntaxhighlight lang='go' run> // https://gobyexample.com/closures package main import "fmt" func intSeq() func() int { i := 0 return...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Go closure
Go 클로저
// https://gobyexample.com/closures
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())
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}