local p=require(script.Parent.copy)local function d(p)return p end local function T(p,...)if type(p)=="\102\117\110\099\116\105\111\110"then return p(...)end end local function J(J,C,O,s)local r=type(J)assert(r=="\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 "..r)local L=type(C)assert(L=="\110\117\109\098\101\114"and C%1==0,"\101\120\112\101\099\116\101\100 \097\110 \105\110\116\101\103\101\114 \102\111\114 \115\101\099\111\110\100 \097\114\103\117\109\101\110\116\044 \103\111\116 "..L)local G=p(J)local M O=O or d if G[C]~=nil then M=O(G[C],C)T(s,true,M,C)else M=T(s,false,C)end G[C]=M return G end return J

local copy = require(script.Parent.copy)

local function noUpdate(value)
	return value
end

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

local function update(list, index, updater, callback)
	local listType = type(list)
	assert(listType == "table", "expected a table for first argument, got " .. listType)

	local indexType = type(index)
	assert(indexType == "number" and index % 1 == 0, "expected an integer for second argument, got " .. indexType)

	local new = copy(list)
	local value

	updater = updater or noUpdate

	if new[index] ~= nil then
		value = updater(new[index], index)
		call(callback, true, value, index)
	else
		value = call(callback, false, index)
	end
	
	new[index] = value

	return new
end

return update