From 3c6aaf1a765bf4bb0f5caf01613974653b36c88d Mon Sep 17 00:00:00 2001 From: Sheepolution Date: Tue, 1 Mar 2022 02:03:33 +0100 Subject: [PATCH 1/2] Return table in foreach for chaining --- functional.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/functional.lua b/functional.lua index 127b430..8165652 100644 --- a/functional.lua +++ b/functional.lua @@ -38,6 +38,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 From f36946ace455228d8b4fdd6ef3f7e0ff6b7f07cf Mon Sep 17 00:00:00 2001 From: Sheepolution Date: Tue, 1 Mar 2022 03:01:39 +0100 Subject: [PATCH 2/2] Add comment to foreach regarding new behaviour --- functional.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/functional.lua b/functional.lua index 8165652..d6748d2 100644 --- a/functional.lua +++ b/functional.lua @@ -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)