Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Lua

Idiom #166 Concatenate two lists

Create the list ab containing all the elements of the list a, followed by all the elements of the list b.

ab = {}

table.foreach(a, function(k, v) table.insert(ab, v) end)
table.foreach(b, function(k, v) table.insert(ab, v) end)
ab = {}

table.move(a, 1, #a, 1, ab)
table.move(b, 1, #b, #ab + 1, ab)
(def ab (concat a b))

New implementation...