Skip to content

Instantly share code, notes, and snippets.

@mduvall
Created April 6, 2014 05:45
Show Gist options
  • Save mduvall/10001961 to your computer and use it in GitHub Desktop.
Save mduvall/10001961 to your computer and use it in GitHub Desktop.
What's the idiomatic way to concat a bunch of slices?
// Assume the following variables...
// r [][]string
// s string
// p []string
//
// Problem: append to r the []string x where x is p[1:] + [s] + p[:1]
// 1. Do crazy appends
r = append(r, append(append(append(make([]string, 0), p[:i]...), s), p[i:]...))
// 2. ?
@mduvall
Copy link
Author

mduvall commented Apr 6, 2014

One step closer, still looks a bit unreadable...

a = append(a[:i], append([]T{x}, a[i:]...)...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment