Functional Table Processing
Pipeline Result
Combine mapping, filtering, and reducing in one pass.
pipeline result
A processing pipeline can transform values, filter them, and reduce the kept values to one result.
Pipeline Result
pipeline_result.lua
Replay: real traced execution (multi-file project)
local bonus = 1
local total = 0
for _, value in ipairs({1, 2, 3}) do
local mapped = value + bonus
if mapped % 2 == 0 then
total = total + mapped
end
end
print("bonus=" .. bonus)
print("total=" .. total)
local bonus = 0
local total = 0
for _, value in ipairs({1, 2, 3}) do
local mapped = value + bonus
if mapped % 2 == 0 then
total = total + mapped
end
end
print("bonus=" .. bonus)
print("total=" .. total)
local bonus = 3
local total = 0
for _, value in ipairs({1, 2, 3}) do
local mapped = value + bonus
if mapped % 2 == 0 then
total = total + mapped
end
end
print("bonus=" .. bonus)
print("total=" .. total)
bonus ← 1, total ← 0
1local bonus→ 1 = 1 --@bonus=0, 32local total→ 0 = 0mapped ← 2
pass 1 of 34for _1, value1 in ipairs({1, 2, 3}) do5 local mapped→ 2 = value1 + bonus16 if mapped % 2 == 0 thenAll 3 passes — pass 1 is the card above pass _valuemappedtotal1 1 1 2 0 → 2 2 2 2 3 — 3 3 3 4 2 → 6 total ← 2
pass 1 of 25local mapped = value + bonus6if mapped2 % 2 == 0 then7 total→ 2 = total + mapped28endtotal ← 6
pass 2 of 25local mapped = value + bonus6if mapped4 % 2 == 0 then7 total→ 6 = total + mapped48endprint("bonus=" .. bonus)
11print("bonus=" .. bonus1)12print("total=" .. total6)outputbonus=1 total=6
bonus ← 0, total ← 0
1local bonus→ 0 = 02local total→ 0 = 0mapped ← 1
pass 1 of 34for _1, value1 in ipairs({1, 2, 3}) do5 local mapped→ 1 = value1 + bonus06 if mapped % 2 == 0 thenAll 3 passes — pass 1 is the card above pass _valuemappedtotal1 1 1 1 — 2 2 2 2 0 → 2 3 3 3 3 — total ← 2
5local mapped = value + bonus6if mapped2 % 2 == 0 then7 total→ 2 = total + mapped28endprint("bonus=" .. bonus)
11print("bonus=" .. bonus0)12print("total=" .. total2)outputbonus=0 total=2
bonus ← 3, total ← 0
1local bonus→ 3 = 32local total→ 0 = 0mapped ← 4
pass 1 of 34for _1, value1 in ipairs({1, 2, 3}) do5 local mapped→ 4 = value1 + bonus36 if mapped % 2 == 0 thenAll 3 passes — pass 1 is the card above pass _valuemappedtotal1 1 1 4 0 → 4 2 2 2 5 — 3 3 3 6 4 → 10 total ← 4
pass 1 of 25local mapped = value + bonus6if mapped4 % 2 == 0 then7 total→ 4 = total + mapped48endtotal ← 10
pass 2 of 25local mapped = value + bonus6if mapped6 % 2 == 0 then7 total→ 10 = total + mapped68endprint("bonus=" .. bonus)
11print("bonus=" .. bonus3)12print("total=" .. total10)outputbonus=3 total=10