Last active
December 20, 2015 21:09
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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