The book I'm reading about Erlang has exercises in the back of it and one is to re-create the lists:append function.
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.
So far the only approach that I could think of is to do something like:
concat([], _, Results)->
Results;
concat(_, [], Results)->
Results;
concat([Ah|At],B,Results) ->
concat(At,B,[Ah|Results]).
But I know this is incorrect...
Any suggestions on how to go about doing this?
EDIT: To clarify the question, here is an example input and output:
Input: [[1,2,3],[],[4,5],[6]] Output: [1,2,3,4,5,6]
After working a while, I came up with this code as well:
append([A|[B|[T|[]]]]) ->
append([A++B|T]);
append([H|T]) ->
H++T.
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?