org.http4k.connect.Paged.kt Maven / Gradle / Ivy
package org.http4k.connect
import dev.forkhandles.result4k.Result
import dev.forkhandles.result4k.map
/**
* Represents a Paged response
*/
interface Paged: Iterable {
fun token(): Token?
val items: List
override fun iterator() = items.iterator()
}
/**
* Superclass for all Paged actions
*/
interface PagedAction, Self : PagedAction> :
Action> {
fun next(token: Token): Self
}
/**
* Paginate the response of the passed action
*/
fun , Rsp : Paged> paginated(
fn: (Action) -> Result, action: Action
): Sequence, RemoteFailure>> {
var nextRequest: Action? = action
return generateSequence {
nextRequest
?.let {
fn(it).map { rsp ->
nextRequest = rsp.token()?.let(it::next)
rsp.items
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy