Functions_Closures

A variadic function accept varying numbers of arguments. To declare a variadic function, the type of of the final parameter is preceded by an ellipsis, “…” …int ellipsis defined a function can be called with any number of arguments of this type vals is []int slice, can be access this Read more…

Methods with Struct

The Point struct type has two fields, x and y of float64 A method is defined with use of the keyword “func” just like a definition of the function. Just after func keyword, the defined fields of struct used in the body of code of the function as a receiver. Read more…

Function with a function return.

func foo() func() int { } A function name foo() without parameters/arguments return anonymous function without parameter/arguments return an int type. Empty body In the line 2, the return for calling func foo() and follow up with the code of anonmoys function func() with return int type signature. In this Read more…

Function closures

Go functions may be closures. A closure is a function value that references variables from outside its body. The function may access and assign to the referenced variables; in this sense the function is “bound” to the variables https://tour.golang.org/moretypes/25

Memoization Technique (Fibonacci)

Let’s utilize a memoization technique to speed up our Fibonacci calculation. Memoization is an optimization technique used to increase performance by storing the results of expensive function calls and returning the cached result when the same input occurs again.

Recursive Function

Fibonacci sequence – a simple recursion and two performance improvements The Fibonacci sequence is a sequence of numbers where each number is equal to the previous two numbers added together. Here’s an example of this: So, 1 plus 1 is 2, 2 plus 3 is 5, 5 plus 8 is 13, and Read more…