summaryrefslogtreecommitdiff
path: root/xmake/core/base/table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/core/base/table.lua')
-rw-r--r--xmake/core/base/table.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 1f3e79add..c08526c34 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -309,5 +309,31 @@ function table.values(tab)
return valueset, n
end
+-- map values to a new table
+function table.map(tab, mapper)
+
+ assert(tab)
+ assert(mapper)
+
+ local newtab = {}
+ for k, v in pairs(tab) do
+ newtab[k] = mapper(k, v)
+ end
+ return newtab
+end
+
+-- map values to a new array
+function table.imap(arr, mapper)
+
+ assert(arr)
+ assert(mapper)
+
+ local newarr = {}
+ for k, v in ipairs(arr) do
+ table.insert(newarr, mapper(k, v))
+ end
+ return newarr
+end
+
-- return module: table
return table