local R=script.Parent local p=require(R.copy)local E=R.Parent local d=require(E.t)local function t(R)return R end local function N(R,...)if type(R)=="\102\117\110\099\116\105\111\110"then return R(...)end end local H=d.optional(d.callback)local Q=d.tuple(d.table,d.any,H,H)local function A(R,E,d,H)assert(Q(R,E,d,H))d=d or t local A=p(R)if A[E]~=nil then A[E]=d(A[E],E)else A[E]=N(H,E)end return A end return A
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