[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Extract a list of keys from table
- From: Shmuel Zeigerman <shmuz@...>
- Date: Fri, 18 Jul 2008 01:32:40 +0300
Alexander Gladysh wrote:
print(
extract_keys(
{ a = 1, b = 2, c = 3 },
"a", "b", "xxx", "c", "yyy"
)
)
--> 1 2 nil 3 nil
An option is using recursive functions:
-- "mapper" is a table:
function map(tab, ...)
if select("#", ...) > 0 then
return tab[...], map(tab, select(2,...))
end
end
-- "mapper" is a function:
function map(func, ...)
if select("#", ...) > 0 then
return func(select(1,...)), map(func, select(2,...))
end
end
--
Shmuel