diff --git a/CHANGELOG.md b/CHANGELOG.md index c93fddd4302..238a31cd99a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.2.1 +* `Pagination` + * `Common`: + * Extension `Pagination#reverse` has been added + ## 0.2.0 * `Repos` diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt new file mode 100644 index 00000000000..f654f2fa81b --- /dev/null +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt @@ -0,0 +1,22 @@ +package dev.inmo.micro_utils.pagination.utils + +import dev.inmo.micro_utils.pagination.* + +/** + * Example: + * + * * `|__f__l_______________________|` will be transformed to `|_______________________f__l__|` + * * `|__f__l_|` will be transformed to `|__f__l_|` + * + * @return Reversed version of this [Pagination] + */ +fun Pagination.reverse(objectsCount: Long): SimplePagination { + if (firstIndex > objectsCount) { + return Pagination(objectsCount.toInt(), size) + } + val firstIndex = (objectsCount - firstIndex - size).toInt() + return Pagination( + firstIndex, + size + ) +}