Skip to content

Instantly share code, notes, and snippets.

@pikajude
Created May 22, 2011 23:55
Show Gist options
  • Select an option

  • Save pikajude/986019 to your computer and use it in GitHub Desktop.

Select an option

Save pikajude/986019 to your computer and use it in GitHub Desktop.
table["map"] = function (tbl, func)
local newtbl = {}
for k, v in pairs(tbl) do
local key, value = (func)(k, v)
if not value then
value = key
key = #newtbl + 1
end
newtbl[key] = value
end
return newtbl
end
for k, v in pairs(table.map({b = "a", c = "b", a = "c"}, function (k, v) return v, tostring(k) end)) do
print(k, v)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment