From 7b5e84f80b3fa11af26301f4ad56ac1beea774da Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 28 May 2022 22:47:06 +0600 Subject: [PATCH] doForAll and getForAll not suspend --- CHANGELOG.md | 3 ++ .../micro_utils/pagination/utils/DoForAll.kt | 16 +++++----- .../micro_utils/pagination/utils/GetAll.kt | 29 +++++++++---------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b44e59ba2d..4682e9d02e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.10.7 +* `Pagination`: + * Now it is possible to use `doForAll*` and `getForAll` functions in non suspend places + ## 0.10.6 * `Versions` diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt index b77f3b59848..63e8cb38eba 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt @@ -2,19 +2,19 @@ package dev.inmo.micro_utils.pagination.utils import dev.inmo.micro_utils.pagination.* -suspend fun doForAll( +inline fun doForAll( initialPagination: Pagination = FirstPagePagination(), paginationMapper: (PaginationResult) -> Pagination?, - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ) { doWithPagination(initialPagination) { block(it).let(paginationMapper) } } -suspend fun doForAllWithNextPaging( +inline fun doForAllWithNextPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ) { doForAll( initialPagination, @@ -23,9 +23,9 @@ suspend fun doForAllWithNextPaging( ) } -suspend fun doAllWithCurrentPaging( +inline fun doAllWithCurrentPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ) { doForAll( initialPagination, @@ -34,7 +34,7 @@ suspend fun doAllWithCurrentPaging( ) } -suspend fun doForAllWithCurrentPaging( +inline fun doForAllWithCurrentPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ) = doAllWithCurrentPaging(initialPagination, block) diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt index 8012a89e47d..da50a9528e2 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt @@ -2,10 +2,10 @@ package dev.inmo.micro_utils.pagination.utils import dev.inmo.micro_utils.pagination.* -suspend fun getAll( +inline fun getAll( initialPagination: Pagination = FirstPagePagination(), paginationMapper: (PaginationResult) -> Pagination?, - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ): List { val results = mutableListOf() doForAll(initialPagination, paginationMapper) { @@ -16,46 +16,45 @@ suspend fun getAll( return results.toList() } -suspend fun R.getAllBy( +inline fun R.getAllBy( initialPagination: Pagination = FirstPagePagination(), paginationMapper: R.(PaginationResult) -> Pagination?, - block: suspend R.(Pagination) -> PaginationResult + block: R.(Pagination) -> PaginationResult ): List = getAll( initialPagination, { paginationMapper(it) }, { block(it) } ) -suspend fun getAllWithNextPaging( +inline fun getAllWithNextPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ): List = getAll( initialPagination, { it.nextPageIfNotEmpty() }, block ) -suspend fun R.getAllByWithNextPaging( +inline fun R.getAllByWithNextPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend R.(Pagination) -> PaginationResult + block: R.(Pagination) -> PaginationResult ): List = getAllWithNextPaging( initialPagination, { block(it) } ) -suspend fun getAllWithCurrentPaging( +inline fun getAllWithCurrentPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult + block: (Pagination) -> PaginationResult ): List = getAll( initialPagination, { it.currentPageIfNotEmpty() }, block ) -suspend fun R.getAllByWithCurrentPaging( +inline fun R.getAllByWithCurrentPaging( initialPagination: Pagination = FirstPagePagination(), - block: suspend R.(Pagination) -> PaginationResult + block: R.(Pagination) -> PaginationResult ): List = getAllWithCurrentPaging( - initialPagination, - { block(it) } -) + initialPagination +) { block(it) }