From 30b70e9984974790b3f42cdbfad9d53e00132679 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 29 Mar 2021 19:48:37 +0600 Subject: [PATCH] replacement of doForAll and getAll --- CHANGELOG.md | 19 +++++----- .../micro_utils/pagination/utils/DoForAll.kt | 35 +++++++++++++++++++ .../micro_utils/pagination/utils/GetAll.kt | 34 +----------------- .../inmo/micro_utils/repos/cache/KVCache.kt | 2 +- .../repos/OneToManyKeyValueRepo.kt | 2 +- .../micro_utils/repos/StandartKeyValueRepo.kt | 2 +- .../pagination/CRUDPaginationExtensions.kt | 2 ++ .../KeyValuePaginationExtensions.kt | 1 + .../OneToManyPaginationExtensions.kt | 1 + 9 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt rename repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt => pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt (52%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3664fe683..c2a0f57b93a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,22 +10,21 @@ * Extension `PaginationResult.thisPageIfNotEmpty` now is typed and will return `PaginationResult?` with the same generic type as income `PaginationResult` * New extension `PaginationResult.currentPageIfNotEmpty` - shortcut for `PaginationResult.thisPageIfNotEmpty` + * New common functions. They were created as replacements for currently available for more comfortable work + with repos pagination: + * `doForAll` + * `doForAllWithNextPaging` + * `doForAllWithCurrentPaging` + * `getAll` + * `getAllWithNextPaging` + * `getAllWithCurrentPaging` * `Coroutines`: * Rewrite `subscribeSafelyWithoutExceptions` * Now `subscribeSafelyWithoutExceptions` will use default handler instead of skipping * New extension `subscribeSafelySkippingExceptions` * `Repos` * New subproject `repos.cache` - this subproject will contain repos with data caching mechanisms - * `Pagination` - * New common functions. They were created as replacements for currently available for more comfortable work - with repos pagination: - * `doForAll` - * `doForAllWithNextPaging` - * `doForAllWithCurrentPaging` - * `getAll` - * `getAllWithNextPaging` - * `getAllWithCurrentPaging` - * Most old `doForAll` methods have been deprecated + * Most old `doForAll` methods have been deprecated ## 0.4.30 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 new file mode 100644 index 00000000000..7a893bb2a24 --- /dev/null +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt @@ -0,0 +1,35 @@ +package dev.inmo.micro_utils.pagination.utils + +import dev.inmo.micro_utils.pagination.* + +suspend fun doForAll( + initialPagination: Pagination = FirstPagePagination(), + paginationMapper: (PaginationResult) -> Pagination?, + block: suspend (Pagination) -> PaginationResult +) { + doWithPagination(initialPagination) { + block(it).let(paginationMapper) + } +} + +suspend fun doForAllWithNextPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +) { + doForAll( + initialPagination, + { it.nextPageIfNotEmpty() }, + block + ) +} + +suspend fun doAllWithCurrentPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +) { + doForAll( + initialPagination, + { it.thisPageIfNotEmpty() }, + block + ) +} diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt similarity index 52% rename from repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt rename to pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt index 3d6b30523e7..bb670684725 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt @@ -1,39 +1,7 @@ -package dev.inmo.micro_utils.repos.pagination +package dev.inmo.micro_utils.pagination.utils import dev.inmo.micro_utils.pagination.* -suspend fun doForAll( - initialPagination: Pagination = FirstPagePagination(), - paginationMapper: (PaginationResult) -> Pagination?, - block: suspend (Pagination) -> PaginationResult -) { - doWithPagination(initialPagination) { - block(it).let(paginationMapper) - } -} - -suspend fun doForAllWithNextPaging( - initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult -) { - doForAll( - initialPagination, - { it.nextPageIfNotEmpty() }, - block - ) -} - -suspend fun doAllWithCurrentPaging( - initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult -) { - doForAll( - initialPagination, - { it.thisPageIfNotEmpty() }, - block - ) -} - suspend fun getAll( initialPagination: Pagination = FirstPagePagination(), paginationMapper: (PaginationResult) -> Pagination?, diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt index b75a741496d..a7248352446 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos.cache import dev.inmo.micro_utils.repos.* -import dev.inmo.micro_utils.repos.pagination.getAllWithNextPaging +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt index e899c78c2e8..001c618851b 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* -import dev.inmo.micro_utils.repos.pagination.getAllWithNextPaging +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import kotlinx.coroutines.flow.Flow interface ReadOneToManyKeyValueRepo : Repo { diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt index 7747120478a..90ad3a0b92f 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* -import dev.inmo.micro_utils.repos.pagination.doAllWithCurrentPaging +import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging import kotlinx.coroutines.flow.Flow interface ReadStandardKeyValueRepo : Repo { diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt index ae2a786b6c3..75478b0a2ae 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt @@ -1,6 +1,8 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo @Deprecated("Will be removed soon due to redundancy. Can be replaced with other doForAll extensions") diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt index d4605b7dd1d..bb9a75b91a7 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo @Deprecated("Will be removed soon due to redundancy") diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt index 47e43a7380c..5e46015a060 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo @Deprecated("Will be removed soon due to redundancy")