Skip to content

Instantly share code, notes, and snippets.

@domluna
Last active December 20, 2015 21:09
Show Gist options
  • Save domluna/6195536 to your computer and use it in GitHub Desktop.
Save domluna/6195536 to your computer and use it in GitHub Desktop.
You ever have two slices in Go you wanted to combine? Of course you did. Did you use a for loop? Of course you did. Now what if I told you that for loop was bogus!
a := []int{1,2,3}
b := []int{4,5,6}
// Bad way
for _, number := range b {
a = append(a, number)
}
// Super awesome way
a = append(a, b...)
// a = [1 2 3 4 5 6]
// append's second argument is actually variadic meaning you can pass multiple values to append to the slice.
// b... is the syntactic way saying im passing the values of the slice not the slice itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment