local s=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local u=require(s.Packages.iter)local c=5000 local function E(s)local u=Instance.new("\077\101\115\104\080\097\114\116")return s^99 end local function k(s)local u={}for c=1,40,1 do table.insert(u,s[c])end return u end local function h(s)return(s:take(40)):collect()end return{ParameterGenerator=function()local s=table.create(c)for u=1,c,1 do s[u]=math.random(10000)end return table.freeze(s)end,Functions={loop=function(s,u)local c={}for s,u in u do table.insert(c,E(u))end k(c)end,iter=function(s,c)local k=(u.new(c)):map(function(s,u)return E(u)end)h(k)end}}
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local iter = require(ReplicatedStorage.Packages.iter)

local ARRAY_SIZE = 5000

local function someExpensiveFn(value)
	local _ = Instance.new("MeshPart")
	return value ^ 99
end

local function consumeTable(tb)
	local newTable = {}
	for i = 1, 40 do
		table.insert(newTable, tb[i])
	end
	return newTable
end

local function consumeIterator(iterator)
	return iterator:take(40):collect()
end

return {
	ParameterGenerator = function()
		local arr = table.create(ARRAY_SIZE)
		for i = 1, ARRAY_SIZE do
			arr[i] = math.random(10000)
		end
		return table.freeze(arr)
	end,

	Functions = {
		-- 7.39 ms
		loop = function(_, t)
			-- In a practical scenario, if the consumer code is separate from the transformation code,
			-- you'd need to apply the transformation to the entire table even if you only need part of it
			-- because you don't know how much of the table the consumer will need
			local checkedValues = {}
			for _, value in t do
				table.insert(checkedValues, someExpensiveFn(value))
			end
			consumeTable(checkedValues)
		end,

		-- 0.11 ms
		iter = function(_, t)
			-- Using iterators we can avoid applying the transformation to the entire table
			local iterator = iter.new(t):map(function(_, value)
				return someExpensiveFn(value)
			end)
			consumeIterator(iterator)
		end,
	},
}
