about summary refs log tree commit diff stats
path: root/util.lua
diff options
context:
space:
mode:
authorCase Duckworth2024-03-10 21:39:53 -0500
committerCase Duckworth2024-03-10 21:39:53 -0500
commita72ff678da253fce46e8e4648f6e4cf5ce1ea9b4 (patch)
treea82501fca97f4adc272d05145548d10cabe3ea2a /util.lua
parentUgghhhh totally not working (diff)
downloadlam-a72ff678da253fce46e8e4648f6e4cf5ce1ea9b4.tar.gz
lam-a72ff678da253fce46e8e4648f6e4cf5ce1ea9b4.zip
uh new start
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua33
1 files changed, 1 insertions, 32 deletions
diff --git a/util.lua b/util.lua index 1059edf..938848c 100644 --- a/util.lua +++ b/util.lua
@@ -1,42 +1,11 @@
1--- lam.util 1--- lam.util
2 2
3local util = {} 3local util = {}
4table.unpack = table.unpack or unpack 4local unpack = table.unpack or unpack
5
6function util.table (x)
7 if type(x) == "table" then
8 return x
9 else
10 return { x }
11 end
12end
13 5
14function util.pop (tbl) 6function util.pop (tbl)
15 return table.remove(tbl, 1) 7 return table.remove(tbl, 1)
16end 8end
17 9
18function util.car (tbl)
19 return tbl[1]
20end
21
22function util.cdr (tbl)
23 local t = {}
24 for i = 2, #tbl do t[i-1] = tbl[i] end
25 return t
26end
27
28function util.reduce (tbl, seed, fn)
29 if #tbl == 0 then return seed end
30 return util.reduce(tbl, fn(seed, util.pop(tbl)), fn)
31end
32
33function util.map (fn, tbl)
34 local out = {}
35 for k, v in pairs(tbl) do
36 out[k] = fn(v)
37 end
38 return out
39end
40
41--- 10---
42return util 11return util