Appending elements to a list

So basically this?

def foo(list) when is_list(list) do
  for i <- (Enum.count(list) - 1), do: List.delete_at(list, i)
end

The culprit is, that this is O(n²), since List.delete_at/2 is O(n) and we call it n times… I’m not sure though if one can do this in something better… Intuitively O(n) can’t be achieved, but perhaps something inbetween?


Anyway… I’m not sure what this has to do with “appending to a list” as written in the title… Can you perhaps think about it and rephrase the question?