pagingFlow

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.

Return

A Flow emitting each item as its page is fetched.

Parameters

initialPagingOptions

Paging options used to fetch the first page.

fetchPage

Fetches a page for the given PagingOptions.

maxPages

Maximum number of pages to fetch.

Throws

IllegalArgumentException

if maxPages is less than 1; thrown when the flow is collected, not when this function is called.


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.

Return

A Flow emitting each item as its page is fetched.

Parameters

initialPagingOptions

Paging options used to fetch the first page.

fetchPage

Fetches a page for the given PagingOptions.

nextUrlSelector

Extracts the next page URL from a page payload.

itemsSelector

Extracts the list of items from a page payload.

maxPages

Maximum number of pages to fetch.

Throws

IllegalArgumentException

if maxPages is less than 1; thrown when the flow is collected, not when this function is called.