fold
fold
<lst>:fold(foo(x, item, pos), initval)
Applica foo su tutti gli elementi della lista passando l'accumulatore x (valore iniziale "initval") e l'elemento corrente.
local a = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}
local b = XTable(a)
:fold(function(sentence, word) return sentence .. " " .. word; end, "")
--> "The quick brown fox jumps over the lazy dog"
local orders = {
{id=2, product="Computer", price=1000, year=2010},
{id=2, product="Book", price=50, year=2012},
{id=2, product="TV", price=800, year=2011},
}
local b = XTable(orders)
:fold(function(x, item, i) return x + item.price; end, 1000))
--> 2850