All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecwid.apiclient.v3.dto.common.Paging.kt Maven / Gradle / Ivy

There is a newer version: 0.347.0
Show newest version
package com.ecwid.apiclient.v3.dto.common

interface PagingRequest> {
	val offset: Int
	fun copyWithOffset(offset: Int): Self
}

interface PagingResult {
	val limit: Int
	val items: List
}

fun , Result : PagingResult, Item> fetchPagesAsItemSequence(
	request: Request,
	serviceMethod: (Request) -> Result,
): Sequence = sequence {
	@Suppress("NAME_SHADOWING")
	var request = request

	do {
		val result = serviceMethod.invoke(request)
		yieldAll(result.items)
		request = request.copyWithOffset(request.offset + result.items.size)
	} while (result.items.size >= result.limit)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy