Skip to content

Commit

Permalink
add doc for lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
tsingbx committed Oct 13, 2023
1 parent 3103721 commit c6017d5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 205-Lambda-expressions/lambda.gop
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"

0 comments on commit c6017d5

Please sign in to comment.