Skip to content

Commit

Permalink
feat: Array.map should handle no return same as nil return (#4967)
Browse files Browse the repository at this point in the history
* feat(Array): Let Array.map not error on bool false or undefined return

* do not butcher false

* soem test case for it
  • Loading branch information
hjpalpha authored Oct 30, 2024
1 parent 05bbc71 commit c2d8a76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/array_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion standard/array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2d8a76

Please sign in to comment.