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 slice using index or for..range

# Category: Functions_Closures

## 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. It takes a variable of… Continue reading Methods with Struct

## 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 body of anonymous func() on… Continue reading Function with a function return.

## Factorial (both not recursive and recursive)

## 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 so on. The Rule is xn =… Continue reading Recursive Function