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]

Pass slice as a function argument

In Go, the function parameters are passed by value. With respect to use slice as a function argument, that means the function will get the copies of the slice: a pointer which points to the starting address of the underlying array, accompanied by the length and capacity of the slice. Oh boy! Since you know the address of the memory which is used to store the data, you can tweak the slice now. [Read More]