mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-04 23:59:29 +00:00
add in memory map based crud implementation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package dev.inmo.micro_utils.pagination.utils
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
|
||||
fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
var i = 0
|
||||
val result = mutableListOf<T>()
|
||||
val lowerIndex = with.firstIndex
|
||||
val greatestIndex = with.lastIndex
|
||||
for (item in this) {
|
||||
when {
|
||||
i < lowerIndex || i > greatestIndex -> i++
|
||||
else -> {
|
||||
result.add(item)
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.createPaginationResult(with, i.toLong())
|
||||
}
|
||||
|
||||
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
return subList(with.firstIndex, with.lastIndex + 1).createPaginationResult(
|
||||
with,
|
||||
size.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
return this.drop(with.firstIndex).take(with.size).createPaginationResult(
|
||||
with,
|
||||
size.toLong()
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user