Skip to content

Commit

Permalink
feature(table): Add slice function
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrady committed Aug 30, 2020
1 parent bcaab4a commit ead33fc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,17 @@ function module.uniq(t)
return _t
end

-- Returns a subset of the given table consisting of entries matching the given list of keys.
function module.slice(t, keys)
if not keys then
return
end

local _t = {}
for _,v in ipairs(keys) do _t[v] = t[v] end

return _t
end

-----------
return module

0 comments on commit ead33fc

Please sign in to comment.