From 9b16c635b35aab56e0f3f52f092a3ae829116c57 Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Thu, 21 May 2026 12:29:23 +0900 Subject: [PATCH 1/3] rewrite Array.interleave --- lua/wikis/commons/Array.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lua/wikis/commons/Array.lua b/lua/wikis/commons/Array.lua index 0bbf15d7bd7..9c2216cf408 100644 --- a/lua/wikis/commons/Array.lua +++ b/lua/wikis/commons/Array.lua @@ -727,13 +727,12 @@ end ---@param x T ---@return (V|T)[] function Array.interleave(elements, x) - local size = #elements - return Array.flatMap(elements, function(element, index) - if index == size then - return {element} - end - return {element, x} - end) + local ret = {elements[1]} + for i = 2, #elements do + table.insert(ret, x) + table.insert(ret, elements[i]) + end + return ret end return Array From 5f50634875fcd7c9e5cbb0ee39155e4e938753fb Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Thu, 21 May 2026 12:37:31 +0900 Subject: [PATCH 2/3] more test cases --- lua/spec/array_spec.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/spec/array_spec.lua b/lua/spec/array_spec.lua index 91291285fb5..92fb5b589fd 100644 --- a/lua/spec/array_spec.lua +++ b/lua/spec/array_spec.lua @@ -310,6 +310,8 @@ describe('array', function() describe('Interleave', function () it('works', function() assert.are_same({'a', ' ', 'b', ' ', 'c'}, Array.interleave({'a', 'b', 'c'}, ' ')) + assert.are_same({'a'}, Array.interleave({'a'}, ' ')) + assert.are_same({}, Array.interleave({}, ' ')) end) end) end) From 9862ae24c5cb7d4529abb634c0c921fe3bbb51fa Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Thu, 21 May 2026 14:52:27 +0900 Subject: [PATCH 3/3] another test case --- lua/spec/array_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/spec/array_spec.lua b/lua/spec/array_spec.lua index 92fb5b589fd..820def2d1a9 100644 --- a/lua/spec/array_spec.lua +++ b/lua/spec/array_spec.lua @@ -313,5 +313,10 @@ describe('array', function() assert.are_same({'a'}, Array.interleave({'a'}, ' ')) assert.are_same({}, Array.interleave({}, ' ')) end) + + it('with nested array', function () + local a, b = Array.range(1, 3), math.pi + assert.are_same({{1, 2, 3}, ' ', b}, Array.interleave({a, b}, ' ')) + end) end) end)