Functional literals

A functional literal just represents an anonymous function. You can assign functional literal to a variable: package main import ( "fmt" ) func main() { f := func() { fmt.Println("Hello, भारत!") } f() } Or invoke functional literal directly (Please notice the () at the end of functional literal): package main import ( "fmt" ) func main() { func() { fmt.Println("Hello, भारत!") }() } The above 2 programs both output “Hello, भारत!”. [Read More]

Go functions

A function can take zero or more typed arguments. The type comes after the variable name. Functions can be defined to return any number of values that are always typed. package main import "fmt" func add(x int, y int) int { return x + y } func main() { fmt.Println(add(42, 13)) } Go Tour Functions example In the following example, instead of declaring the type of each parameter, we only declare one type that applies to both. [Read More]