diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginatedIterable.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginatedIterable.kt index 035dabbae10..26bf118ad54 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginatedIterable.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginatedIterable.kt @@ -14,9 +14,9 @@ class PaginatedIterator( override fun next(): T { if (currentStack.isEmpty()) { val resultPagination = paginationResultGetter.invoke(pagination) - pagination = resultPagination.nextPage() currentStack.addAll(resultPagination.results) require(currentStack.isNotEmpty()) { "There is no elements left" } + pagination = resultPagination.nextPage() } return currentStack.removeFirst() }