collectAllItemsByCursor

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.

Return

The API response including status code and parsed Spotify payload; on the first error response, that error is returned as-is instead of the collected items.

Parameters

firstPageResponse

The already-fetched first page response.

nextCursorSelector

Extracts the next cursor (after token) from a page payload.

itemsSelector

Extracts the list of items from a page payload.

fetchNext

Fetches the next page for the given cursor.

maxPages

Maximum number of pages to fetch, including the first page.

Throws

IllegalArgumentException

if maxPages is less than 1.


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.

Return

The API response including status code and parsed Spotify payload; on the first error response, that error is returned as-is instead of the collected items.

Parameters

firstPageResponse

The already-fetched first page response.

fetchNext

Fetches the next page for the given cursor.

maxPages

Maximum number of pages to fetch, including the first page.

Throws

IllegalArgumentException

if maxPages is less than 1.