From 23d6644dbe76e22d8558657bfede7b5d471d6383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Vulquin?= Date: Wed, 7 Aug 2024 21:51:15 +0200 Subject: nvim: rework mixed-table macro I didn't like that you couldn't keep mixing and matching, so I made it so you can. In the process, I also implemented even?, odd?, filter, mapcat, flat, and concat. Some of them didn't end up needing to exist, and the entire :toast. namespace does need to be cleaned up. Then again, it's not like I'm selling this like an alternative stdlib. I should really try and port all of clojure.core though, it'd be funny. --- dot_config/nvim/lua/toast/table.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'dot_config/nvim/lua/toast/table.lua') diff --git a/dot_config/nvim/lua/toast/table.lua b/dot_config/nvim/lua/toast/table.lua index a898a5e..e9c1baf 100644 --- a/dot_config/nvim/lua/toast/table.lua +++ b/dot_config/nvim/lua/toast/table.lua @@ -2,9 +2,8 @@ local function from_pairs(t, _3fmut) local out = (_3fmut or {}) for _, _1_ in ipairs(t) do - local _each_2_ = _1_ - local k = _each_2_[1] - local v = _each_2_[2] + local k = _1_[1] + local v = _1_[2] out[k] = v end return out @@ -13,5 +12,14 @@ local function insert(t, ...) table.insert(t, ...) return t end +local function concat(...) + local out = {} + for _, xs in ipairs({...}) do + for _0, v in ipairs(xs) do + insert(out, v) + end + end + return out +end local unpack = (table.unpack or unpack) -return {["from-pairs"] = from_pairs, insert = insert, unpack = unpack} +return {["from-pairs"] = from_pairs, insert = insert, unpack = unpack, concat = concat} -- cgit v1.2.3