more fixes:)

This commit is contained in:
InsanusMokrassar 2020-11-03 20:07:33 +06:00
parent 2f42b30f87
commit eaba9173ae
1 changed files with 6 additions and 1 deletions

View File

@ -21,7 +21,12 @@ 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.lastIndexExclusive, size)).createPaginationResult(
val firstIndex = maxOf(with.firstIndex, 0)
val lastIndex = minOf(with.lastIndexExclusive, size)
if (firstIndex > lastIndex) {
return emptyPaginationResult()
}
return subList(firstIndex, lastIndex).createPaginationResult(
with,
size.toLong()
)