change order in iterable to skip changing of pagination on no left elements error

This commit is contained in:
InsanusMokrassar 2020-12-01 15:48:37 +06:00
parent c25e3f5867
commit e38094df58

View File

@ -14,9 +14,9 @@ class PaginatedIterator<T>(
override fun next(): T { override fun next(): T {
if (currentStack.isEmpty()) { if (currentStack.isEmpty()) {
val resultPagination = paginationResultGetter.invoke(pagination) val resultPagination = paginationResultGetter.invoke(pagination)
pagination = resultPagination.nextPage()
currentStack.addAll(resultPagination.results) currentStack.addAll(resultPagination.results)
require(currentStack.isNotEmpty()) { "There is no elements left" } require(currentStack.isNotEmpty()) { "There is no elements left" }
pagination = resultPagination.nextPage()
} }
return currentStack.removeFirst() return currentStack.removeFirst()
} }