Advertisement
Koepnick

closures

Jan 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.21 KB | None | 0 0
  1. // Closures are functions that return anonymous functions
  2.  
  3. func demo() func() int {
  4.     out := 0
  5.     return func() int {
  6.         out++
  7.         return out
  8.     }
  9. }
  10. ...
  11. test := demo()
  12. val := test()       // 0
  13. val()               // 1
  14. val()               // 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement