Skip to content

Commit

Permalink
Improve map and set value constructors
Browse files Browse the repository at this point in the history
they can now take arguments to add to the value immediately
  • Loading branch information
AstroSnail committed Jan 8, 2025
1 parent da39831 commit b1ee724
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions terms-generators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,15 @@ end
---@field default_print fun(MapValue, ...)

local map_type_mt = {
__call = function(self)
__call = function(self, ...)
local val = {
_map = {},
}
setmetatable(val, self)
local args = table.pack(...)
for i = 1, args.n, 2 do
val:set(args[i], args[i + 1])
end
return val
end,
__eq = function(left, right)
Expand Down Expand Up @@ -475,11 +479,15 @@ define_map = U.memoize(define_map)
---@field default_print fun(SetValue, ...)

local set_type_mt = {
__call = function(self)
__call = function(self, ...)
local val = {
_set = {},
}
setmetatable(val, self)
local args = table.pack(...)
for i = 1, args.n do
val:put(args[i])
end
return val
end,
__eq = function(left, right)
Expand Down

0 comments on commit b1ee724

Please sign in to comment.