mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 13:53:49 +00:00
add optionallyReverse extensions
This commit is contained in:
parent
7a9b7d98a1
commit
85b3e48d18
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.9.4
|
||||
|
||||
* `Pagination`:
|
||||
* `Common`:
|
||||
* Add several `optionallyReverse` functions
|
||||
|
||||
## 0.9.3
|
||||
|
||||
* `Versions`:
|
||||
|
@ -38,3 +38,17 @@ fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
size.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
fun <T> Iterable<T>.optionallyReverse(reverse: Boolean) = if (reverse) {
|
||||
reversed()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
inline fun <reified T> Array<T>.optionallyReverse(reverse: Boolean) = if (reverse) {
|
||||
Array(size) {
|
||||
get(lastIndex - it)
|
||||
}
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
@ -26,3 +26,15 @@ fun Pagination.reverse(datasetSize: Long): SimplePagination {
|
||||
* Shortcut for [reverse]
|
||||
*/
|
||||
fun Pagination.reverse(objectsCount: Int) = reverse(objectsCount.toLong())
|
||||
|
||||
fun Pagination.optionallyReverse(objectsCount: Int, reverse: Boolean) = if (reverse) {
|
||||
reverse(objectsCount)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
fun Pagination.optionallyReverse(objectsCount: Long, reverse: Boolean) = if (reverse) {
|
||||
reverse(objectsCount)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user