From a9b699afdd89f1f01cef53759af435c28d9dbc4c Mon Sep 17 00:00:00 2001 From: "Jeremy S. Postelnek" Date: Mon, 24 Jan 2022 16:27:49 -0500 Subject: [PATCH] Update functional.lua --- functional.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/functional.lua b/functional.lua index 3ed3e8a..4196a91 100644 --- a/functional.lua +++ b/functional.lua @@ -64,17 +64,13 @@ function functional.map(t, f) end -- map a sequence (see functional.map) --- when the function returns an index, map it there -function functional.map_index(t, f) +-- the function must return an index and value to map appropriately +function functional.splat(t, f) local result = {} for i = 1, #t do local v, pos = f(t[i], i) - if v ~= nil then - if not pos then - table.insert(result, v) - else - result[pos] = v - end + if v ~= nil and pos ~= nil then + result[pos] = v end end return result