function map(func, tbl) local newtbl = {} for i,v in pairs(tbl) do newtbl[i] = func(v) end return newtbl end -- filter(function, table) -- e.g: filter(is_even, {1,2,3,4}) -> {2,4} function filter(func, tbl) local newtbl= {} for _,v in pairs(tbl) do if func(v) then table.insert(newtbl, v) end end return newtbl end