local A=script.Parent local Z=require(A.copy)local T=A.Parent local j=require(T.t)local function o(A)return A end local function W(A,...)if type(A)=="\102\117\110\099\116\105\111\110"then return A(...)end end local g=j.optional(j.callback)local S=j.tuple(j.table,j.integer,g,g)local function y(A,T,j,g)assert(S(A,T,j,g))local y=#A 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))j=j or o local a=Z(A)if a[T]~=nil then a[T]=j(a[T],T)else a[T]=W(g,T)end return a 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