--!strict

local function PageIterator(pages)
	return coroutine.wrap(function()
		local pageNumber = 1
		
		while true do
			for _, item in pages:GetCurrentPage() do
				coroutine.yield(item, pageNumber)
			end
			
			if pages.IsFinished then
				break
			end
			
			pages:AdvanceToNextPageAsync()
			pageNumber += 1
		end
	end)
end

return PageIterator
