forked from goplus/tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
//Go supports anonymous functions (lambdas). Lambda expressions are used when we want to define a function inline without giving it any name. | ||
//The way we declare a lambda depends on how we want to use it. It can be defined only, or defined and executed. | ||
|
||
//If we want a lambda to be defined without being executed, we only omit its identifier. | ||
func returnLambda() func(string) { | ||
return func(msg string) { | ||
println msg | ||
} | ||
} | ||
|
||
|
||
|
||
//If we want the lambda to be defined and executed, we omit its identifier and add an argument list in parentheses after the body’s closing curly brace. | ||
func(msg string) { | ||
println msg | ||
}("Hello") | ||
|
||
|
||
|
||
consoleLog := returnLambda() | ||
consoleLog "Hello" |