From c2d8a76ae4080eeb636bd3ffb8ea3af8cf222c0d Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:42:39 +0100 Subject: [PATCH] feat: Array.map should handle no return same as nil return (#4967) * feat(Array): Let Array.map not error on bool false or undefined return * do not butcher false * soem test case for it --- spec/array_spec.lua | 4 ++++ standard/array.lua | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/array_spec.lua b/spec/array_spec.lua index c0a0dd4a29d..ec8d19a5c56 100644 --- a/spec/array_spec.lua +++ b/spec/array_spec.lua @@ -40,6 +40,10 @@ describe('array', function() assert.are_same({2, 4, 6}, Array.map(a, function(x) return 2 * x end)) + assert.are_same({false, false, false}, Array.map(a, function(x) + return false + end)) + assert.are_same({}, Array.map(a, function() end)) end) end) diff --git a/standard/array.lua b/standard/array.lua index a424c97b5ad..3b770caf0ba 100644 --- a/standard/array.lua +++ b/standard/array.lua @@ -88,7 +88,8 @@ end function Array.map(elements, funct) local mappedArray = {} for index, element in ipairs(elements) do - table.insert(mappedArray, funct(element, index)) + local mappedElement = funct(element, index) + table.insert(mappedArray, mappedElement) end return mappedArray end