summaryrefslogtreecommitdiff
path: root/dot_config/nvim/fnl/toast/table.fnl
blob: 17934b228b3b48518c3df8d727dbdbdce6ed1902 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(fn from-pairs [t ?mut]
  "Convert a list of [k v] pairs to a table.
   If an initial table ?mut is provided, it will be mutated and returned."
   (let [out (or ?mut {})]
    (each [_ [k v] (ipairs t)]
     (tset out k v))
    out))

(fn insert [t ...]
  "Like table.insert, but returns the mutated table."
  (table.insert t ...)
  t)

(fn concat [...]
  "Join an arbitrary amount of tables.
   Equivalent to a single 'layer' of flat."
 (let [out []]
   (each [_ xs (ipairs [...])]
    (each [_ v (ipairs xs)]
     (insert out v)))
   out))

(local unpack (or table.unpack unpack))

{: from-pairs
 : insert
 : unpack
 : concat}