Merge pull request #50 from Sheepolution/patch-3

Return table in foreach for chaining
This commit is contained in:
Max Cahill 2022-03-01 13:02:27 +11:00 committed by GitHub
commit f6a18380d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,7 @@ end
--simple sequential iteration, f is called for all elements of t
--f can return non-nil to break the loop (and return the value)
--otherwise returns t for chaining
function functional.foreach(t, f)
for i = 1, #t do
local result = f(t[i], i)
@ -38,6 +39,7 @@ function functional.foreach(t, f)
return result
end
end
return t
end
--performs a left to right reduction of t using f, with seed as the initial value