PagingHelpers

Functions

Link copied to clipboard
suspend fun <T> collectAllItems(firstPageResponse: SpotifyResult<Paging<T>>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, maxPages: Int = 1000): SpotifyResult<List<T>>

Fetches subsequent pages starting from an already-retrieved first Paging page and flattens all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

suspend fun <T> collectAllItems(initialPagingOptions: PagingOptions = PagingOptions(), fetchFirstPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, maxPages: Int = 1000): SpotifyResult<List<T>>

Fetches the first Paging page and then all subsequent pages, flattening all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

suspend fun <TPage, TItem> collectAllItems(firstPageResponse: SpotifyResult<TPage>, nextUrlSelector: (TPage) -> String?, itemsSelector: (TPage) -> List<TItem>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<TPage>, maxPages: Int = 1000): SpotifyResult<List<TItem>>

Fetches subsequent pages starting from an already-retrieved first page and flattens all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

suspend fun <TPage, TItem> collectAllItems(initialPagingOptions: PagingOptions = PagingOptions(), fetchFirstPage: suspend (PagingOptions) -> SpotifyResult<TPage>, nextUrlSelector: (TPage) -> String?, itemsSelector: (TPage) -> List<TItem>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<TPage>, maxPages: Int = 1000): SpotifyResult<List<TItem>>

Fetches the first page and then all subsequent pages, flattening all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

Link copied to clipboard
suspend fun <T> collectAllItemsByCursor(firstPageResponse: SpotifyResult<CursorPaging<T>>, fetchNext: suspend (after: String) -> SpotifyResult<CursorPaging<T>>, maxPages: Int = 1000): SpotifyResult<List<T>>

Fetches subsequent pages starting from an already-retrieved first CursorPaging page using the cursor after token, and flattens all items into a single list until the cursor runs out or maxPages is reached.

suspend fun <TPage, TItem> collectAllItemsByCursor(firstPageResponse: SpotifyResult<TPage>, nextCursorSelector: (TPage) -> String?, itemsSelector: (TPage) -> List<TItem>, fetchNext: suspend (after: String) -> SpotifyResult<TPage>, maxPages: Int = 1000): SpotifyResult<List<TItem>>

Fetches subsequent pages using a cursor (after token) rather than a next URL, and flattens all items into a single list until the cursor runs out or maxPages is reached.

Link copied to clipboard

Extracts limit/offset query parameters from a Spotify "next" page URL.

Link copied to clipboard
fun <T> pagingFlow(initialPagingOptions: PagingOptions = PagingOptions(), fetchPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, maxPages: Int = 1000): Flow<T>

Builds a cold Flow that lazily fetches and emits items across all Paging pages, following Spotify's next URL until it runs out or maxPages is reached.

fun <TPage, TItem> pagingFlow(initialPagingOptions: PagingOptions = PagingOptions(), fetchPage: suspend (PagingOptions) -> SpotifyResult<TPage>, nextUrlSelector: (TPage) -> String?, itemsSelector: (TPage) -> List<TItem>, maxPages: Int = 1000): Flow<TItem>

Builds a cold Flow that lazily fetches and emits items across all pages, following Spotify's next URL until it runs out or maxPages is reached.