-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.lua
45 lines (38 loc) · 848 Bytes
/
utils.lua
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local wezterm = require 'wezterm'
local M = {}
--- Merges two tables, overwriting common elements from table_b
--- @param ... table[]
--- @return table
function M.merge(...)
local args = table.pack(...)
local merged = {}
for i = 1, args.n do
if type(args[i]) == 'string' then
error(args[i])
end
for k, v in pairs(args[i]) do
merged[k] = v
end
end
return merged
end
--- @param module string
--- @return any
function M.req(module)
local m = require(module)
return m
end
--- Returns a new list with function applied to each element of the list
--- @generic T
--- @generic G
--- @param list T[]
--- @param func fun(t: T): G
--- @return G[]
function M.map(list, func)
local mapped = {}
for i, v in ipairs(list) do
mapped[i] = func(v)
end
return mapped
end
return M