mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
Merge pull request #50 from Sheepolution/patch-3
Return table in foreach for chaining
This commit is contained in:
commit
f6a18380d4
@ -31,6 +31,7 @@ end
|
|||||||
|
|
||||||
--simple sequential iteration, f is called for all elements of t
|
--simple sequential iteration, f is called for all elements of t
|
||||||
--f can return non-nil to break the loop (and return the value)
|
--f can return non-nil to break the loop (and return the value)
|
||||||
|
--otherwise returns t for chaining
|
||||||
function functional.foreach(t, f)
|
function functional.foreach(t, f)
|
||||||
for i = 1, #t do
|
for i = 1, #t do
|
||||||
local result = f(t[i], i)
|
local result = f(t[i], i)
|
||||||
@ -38,6 +39,7 @@ function functional.foreach(t, f)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
--performs a left to right reduction of t using f, with seed as the initial value
|
--performs a left to right reduction of t using f, with seed as the initial value
|
||||||
|
Loading…
Reference in New Issue
Block a user