commonMain.dev.inmo.micro_utils.pagination.utils.OptionallyReverse.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro_utils.pagination.common-jvm Show documentation
Show all versions of micro_utils.pagination.common-jvm Show documentation
It is set of projects with micro tools for avoiding of routines coding
package dev.inmo.micro_utils.pagination.utils
fun Iterable.optionallyReverse(reverse: Boolean): Iterable = when (this) {
is List -> optionallyReverse(reverse)
is Set -> optionallyReverse(reverse)
else -> if (reverse) {
reversed()
} else {
this
}
}
fun List.optionallyReverse(reverse: Boolean): List = if (reverse) {
reversed()
} else {
this
}
fun Set.optionallyReverse(reverse: Boolean): Set = if (reverse) {
reversed().toSet()
} else {
this
}
inline fun Array.optionallyReverse(reverse: Boolean) = if (reverse) {
Array(size) {
get(lastIndex - it)
}
} else {
this
}