Batching folder contents based on content type (Plone 6 Classic)

Keep in mind, that when you do folder.objectValues() you wake up every object inside this folder.

I'd rather use @@contentlisting view from plone.app.contentlisting like this:

view = folder.restrictedTraverse("@@contentlisting")
ptypes = set()
for it in view(batch=False):
    ptypes.add(it.portal_type)

ptypes will be a distinct list of the item types because of set()

you can then further use view for getting the type constrained list like

folders = view(batch=True, portal_type="Folder")

EDIT: for folders use @@folderListing the unified browser view for folders and collections is @@contentlisting ... sorry.