All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.inmo.micro_utils.pagination.utils.OptionallyReverse.kt Maven / Gradle / Ivy

There is a newer version: 0.22.2
Show newest version
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 - 2024 Weber Informatics LLC | Privacy Policy