local j=script.Parent local g=require(j.copy)local B=j.Parent local N=require(B.t)local function f(j)return j end local function i(j,...)if type(j)=="\102\117\110\099\116\105\111\110"then return j(...)end end local t=N.optional(N.callback)local z=N.tuple(N.table,N.any,t,t)local function v(j,B,N,t)assert(z(j,B,N,t))N=N or f local v=g(j)if v[B]~=nil then v[B]=N(v[B],B)else v[B]=i(t,B)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