variadics

rem: …type is the arg and for usage type is equivalent to []type

func sum(nums ...int) int {
    total := 0
    for _, num := range nums {
        total += num
    }
    return total
}

for calling

  • sum(1,2,3)
  • sum(nums...) where nums is []int

note that the it’s …int and then nums… the dirs are not the same