Functional Table Processing
Filter Values
Keep only values that pass a condition.
Filter Values
filter_values.lua
local limit =
local output = ""
local count = 0
for _, value in ipairs({2, 4, 6, 8}) do
if value >= limit then
count = count + 1
if output ~= "" then
output = output .. ","
end
output = output .. value
end
end
print("limit=" .. limit)
print("count=" .. count)
print("output=" .. output)
local limit =
local output = ""
local count = 0
for _, value in ipairs({2, 4, 6, 8}) do
if value >= limit then
count = count + 1
if output ~= "" then
output = output .. ","
end
output = output .. value
end
end
print("limit=" .. limit)
print("count=" .. count)
print("output=" .. output)
local limit =
local output = ""
local count = 0
for _, value in ipairs({2, 4, 6, 8}) do
if value >= limit then
count = count + 1
if output ~= "" then
output = output .. ","
end
output = output .. value
end
end
print("limit=" .. limit)
print("count=" .. count)
print("output=" .. output)
filter values
Filtering visits every element but only records the values that match the predicate.