com.ecwid.apiclient.v3.dto.common.Paging.kt Maven / Gradle / Ivy
The 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)
}