Variadic Functions

Variadic functions are functions that accept an undetermined number of parameters. The ... symbol followed by an identifier indicates that the parameter will encapsulate all values ​​passed to the function that do not match to a respective parameter.


// A variadic parameter will become
// a slice of your type.
// In this example, ...int
// will become []int.
func Add(numbers ...int) int {
    var res int
    for _, v := range numbers {
        res += v
    }
    return res
}
                        
variadic_functions.go