title: How to create cartesian product
body: <p>I have a list of integers, <code>a = [0, ..., n]</code>. I want to generate all possible combinations of k elements from a; i.e., the cartesian product of the a with itself k times. Note that n and k are both changeable at runtime, so this needs to be at least a somewhat adjustable function. </p>
  
  <p>So if n was 3, and k was 2:</p>
  
  <pre><code>a = [0, 1, 2, 3]
  k = 2
  
  desired = [(0,0), (0, 1), (0, 2), ..., (2,3), (3,0), ..., (3,3)]
  </code></pre>
  
  <p>In python I would use the itertools.product() function:</p>
  
  <pre><code>for p in itertools.product(a, repeat=2):
      print p
  </code></pre>
  
  <p>What's an idiomatic way to do this <strong>in Go</strong>? </p>
  
  <p>Initial guess is a closure that returns a slice of integers, but it doesn't feel very clean.</p>