From fd998c8525760b93294d97b19869aa474a3dabdb Mon Sep 17 00:00:00 2001 From: "Jeremy S. Postelnek" Date: Mon, 24 Jan 2022 16:40:46 -0500 Subject: [PATCH] Update functional.lua --- functional.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/functional.lua b/functional.lua index 4196a91..516a82f 100644 --- a/functional.lua +++ b/functional.lua @@ -64,12 +64,14 @@ function functional.map(t, f) end -- map a sequence (see functional.map) --- the function must return an index and value to map appropriately +-- the function may return an optional index +-- if no index is provided, it will insert as normal function functional.splat(t, f) local result = {} for i = 1, #t do local v, pos = f(t[i], i) - if v ~= nil and pos ~= nil then + if v ~= nil then + pos = (pos == nil and #result + 1) or pos result[pos] = v end end