title: How can I write Erlang's list concatenate without using the lists module?
body: <p>The book I'm reading about Erlang has exercises in the back of it and one is to re-create the lists:append function.</p>
  
  <p>I could do this simply using the ++ operator, but isn't this really slow? And I think the point of the exercise is to do it using list operations that I write.</p>
  
  <p>So far the only approach that I could think of is to do something like:</p>
  
  <pre><code>concat([], _, Results)-&gt;
    Results;
  concat(_, [], Results)-&gt;
    Results;
  concat([Ah|At],B,Results) -&gt;
    concat(At,B,[Ah|Results]).
  </code></pre>
  
  <p>But I know this is incorrect...</p>
  
  <p>Any suggestions on how to go about doing this?</p>
  
  <p>EDIT: To clarify the question, here is an example input and output:</p>
  
  <p>Input: [[1,2,3],[],[4,5],[6]]
  Output: [1,2,3,4,5,6]</p>
  
  <p>After working a while, I came up with this code as well:</p>
  
  <pre><code>append([A|[B|[T|[]]]]) -&gt;
    append([A++B|T]);
  append([H|T]) -&gt;
    H++T.
  </code></pre>
  
  <p>However, this only works for when the list is size 3. How can I modify this so that it works for any given amount of randomly sized lists?</p>