local O=script.Parent local n=require(O.copy)local t=O.Parent local U=require(t.t)local function P(O)return O end local function u(O,...)if type(O)=="\102\117\110\099\116\105\111\110"then return O(...)end end local p=U.optional(U.callback)local j=U.tuple(U.table,U.integer,p,p)local function y(O,t,U,p)assert(j(O,t,U,p))local y=#O if t<0 then t=y+t end assert(t>0 and t<=y+1,string.format("\105\110\100\101\120 \037\100 \111\117\116 \111\102 \098\111\117\110\100\115 \111\102 \108\105\115\116 \111\102 \108\101\110\103\116\104 \037\100",t,y))U=U or P local S=n(O)if S[t]~=nil then S[t]=U(S[t],t)else S[t]=u(p,t)end return S end return y
local List = script.Parent
local copy = require(List.copy)

local Llama = List.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.integer, optionalCallbackType, optionalCallbackType)

local function update(list, index, updater, callback)
	assert(validate(list, index, updater, callback))

	local len = #list

	if index < 0 then
		index = len + index
	end

	assert(index > 0 and index <= len + 1, string.format("index %d out of bounds of list of length %d", index, len))

	updater = updater or noUpdate

	local new = copy(list)

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

	return new
end

return update