local I=script.Parent local t=require(I.copy)local c=I.Parent local Z=require(c.t)local function s(I)return I end local function J(I,...)if type(I)=="\102\117\110\099\116\105\111\110"then return I(...)end end local r=Z.optional(Z.callback)local Y=Z.tuple(Z.table,Z.any,r,r)local function v(I,c,Z,r)assert(Y(I,c,Z,r))Z=Z or s local v=t(I)if v[c]~=nil then v[c]=Z(v[c],c)else v[c]=J(r,c)end return v end return v
local Dictionary = script.Parent
local copy = require(Dictionary.copy)

local Llama = Dictionary.Parent
local t = require(Llama.t)

local function noUpdate(value)
	return value
end

local function call(callback, ...)
	if type(callback) == "function" then
		return callback(...)
	end
end

local optionalCallbackType = t.optional(t.callback)
local validate = t.tuple(t.table, t.any, optionalCallbackType, optionalCallbackType)

local function update(dictionary, key, updater, callback)
	assert(validate(dictionary, key, updater, callback))

	updater = updater or noUpdate

	local new = copy(dictionary)

	if new[key] ~= nil then
		new[key] = updater(new[key], key)
	else
		new[key] = call(callback, key)
	end

	return new
end

return update