From 5420920243644f4033479b08a0de855080891f7e Mon Sep 17 00:00:00 2001 From: Miguel Pragier Date: Fri, 22 Nov 2019 10:02:19 -0300 Subject: [PATCH] Added closure examples --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index a1ee678..c6cb9ea 100644 --- a/main.go +++ b/main.go @@ -71,9 +71,18 @@ func main() { fmt.Printf("int9By2 is type %T and value %#v\n", int9By2,int9By2) + // printLn is a built-in routine println("Rune is an alias for type int32") fmt.Printf("runeA is type %T and value %c\n", runeA, runeA) fmt.Printf("runeB is type %T and value %c\n", runeB, runeB) + + // Anonymous functions are allowed in go, and you can attrib their bodies to a variable or execute directly when declaring + closure:=func(msg string){fmt.Println(msg)} + + // defer instruction schedule a function to execute just before the current routine exits + defer closure("i'm a deffered closure, and you have to see me by last") + + intResult:=func()int{return 42})() }