title: How to rewrite Erlang combinations algorithm in Elixir?
body: <p>I've been tinkering with Elixir for the last few weeks. I just came across this succinct <a href="http://rosettacode.org/wiki/Combinations#Erlang" rel="noreferrer">combinations algorithm in Erlang</a>, which I tried rewriting in Elixir but got stuck.</p>
  
  <p>Erlang version:</p>
  
  <pre><code>comb(0,_) -&gt;
    [[]];
  comb(_,[]) -&gt;
    [];
  comb(N,[H|T]) -&gt;
    [[H|L] || L &lt;- comb(N-1,T)]++comb(N,T).
  </code></pre>
  
  <p>Elixir version I came up with this, but it's not correct:</p>
  
  <pre><code>def combination(0, _), do: [[]]
  def combination(_, []), do: []
  def combination(n, [x|xs]) do
    for y &lt;- combination(n - 1, xs), do: [x|y] ++ combination(n, xs)
  end
  </code></pre>
  
  <p>Example usage, with incorrect results:</p>
  
  <pre><code>iex&gt; combination(2, [1,2,3])
  [[1, 2, [3], [2, 3]]]
  </code></pre>
  
  <p>Any pointers on what I'm doing wrong?</p>
  
  <p>Thanks!<br>
  Sean</p>