local E=require(script.Parent.copy)local function s(E,s)return E,s end local function c(E,...)if type(E)=="\102\117\110\099\116\105\111\110"then return E(...)end end local function H(H,l,K,N)local k=type(H)assert(k=="\116\097\098\108\101","\101\120\112\101\099\116\101\100 \097 \116\097\098\108\101 \102\111\114 \102\105\114\115\116 \097\114\103\117\109\101\110\116\044 \103\111\116 "..k)assert(l~=nil,"\101\120\112\101\099\116\101\100 \115\101\099\111\110\100 \097\114\103\117\109\101\110\116 \116\111 \098\101 \097\110\121\116\104\105\110\103 \098\117\116 \110\105\108\044 \103\111\116 \110\105\108")local h=E(H)local u,D K=K or s if h[l]~=nil then u,D=K(h[l],l)c(N,true,u,D or l)else u,D=c(N,false,l)end h[D or l]=u return h end return H

local copy = require(script.Parent.copy)

local function noUpdate(v, k)
	return v, k
end

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

local function update(dictionary, key, updater, callback)
	local dictionaryType = type(dictionary)
	assert(dictionaryType == "table", "expected a table for first argument, got " .. dictionaryType)

	assert(key ~= nil, "expected second argument to be anything but nil, got nil")

	local new = copy(dictionary)
	local v, k

	updater = updater or noUpdate

	if new[key] ~= nil then
		v, k = updater(new[key], key)
		call(callback, true, v, k or key)
	else
		v, k = call(callback, false, key)
	end
	
	new[k or key] = v

	return new
end

return update