commonMain.dev.inmo.micro_utils.pagination.utils.OptionallyReverse.kt Maven / Gradle / Ivy
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
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy