mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
fix for paginate (again) and lastIndexExclusive
This commit is contained in:
parent
35913b95be
commit
2f42b30f87
@ -4,6 +4,7 @@
|
||||
|
||||
* `Pagination`
|
||||
* Fixes in function `List#paginate`
|
||||
* Extension property `Pagination#lastIndexExclusive`
|
||||
|
||||
## 0.2.5
|
||||
|
||||
|
@ -28,6 +28,15 @@ interface Pagination {
|
||||
val Pagination.firstIndex: Int
|
||||
get() = page * size
|
||||
|
||||
/**
|
||||
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||
*
|
||||
* [[firstIndex], [lastIndex]]; That means, that for [Pagination] with [Pagination.size] == 10 and [Pagination.page] == 1
|
||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19. Here [Pagination.lastIndexExclusive] == 20
|
||||
*/
|
||||
val Pagination.lastIndexExclusive: Int
|
||||
get() = firstIndex + size
|
||||
|
||||
/**
|
||||
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||
*
|
||||
@ -35,7 +44,7 @@ val Pagination.firstIndex: Int
|
||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
||||
*/
|
||||
val Pagination.lastIndex: Int
|
||||
get() = firstIndex + size - 1
|
||||
get() = lastIndexExclusive - 1
|
||||
|
||||
/**
|
||||
* Calculates pages count for given [datasetSize]
|
||||
|
@ -21,7 +21,7 @@ fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
}
|
||||
|
||||
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
return subList(maxOf(with.firstIndex, 0), (minOf(with.lastIndex, lastIndex)) + 1).createPaginationResult(
|
||||
return subList(maxOf(with.firstIndex, 0), minOf(with.lastIndexExclusive, size)).createPaginationResult(
|
||||
with,
|
||||
size.toLong()
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user