several fixes in optionallyReverse

This commit is contained in:
InsanusMokrassar 2022-01-17 16:11:55 +06:00
parent d619d59947
commit 0202988cae

View File

@ -39,11 +39,25 @@ fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
) )
} }
fun <T> Iterable<T>.optionallyReverse(reverse: Boolean) = if (reverse) { fun <T> Iterable<T>.optionallyReverse(reverse: Boolean): Iterable<T> = when (this) {
is List<T> -> optionallyReverse(reverse)
is Set<T> -> optionallyReverse(reverse)
else -> if (reverse) {
reversed()
} else {
this
}
}
fun <T> List<T>.optionallyReverse(reverse: Boolean): List<T> = if (reverse) {
reversed() reversed()
} else { } else {
this this
} }
fun <T> Set<T>.optionallyReverse(reverse: Boolean): Set<T> = if (reverse) {
reversed().toSet()
} else {
this
}
inline fun <reified T> Array<T>.optionallyReverse(reverse: Boolean) = if (reverse) { inline fun <reified T> Array<T>.optionallyReverse(reverse: Boolean) = if (reverse) {
Array(size) { Array(size) {