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,8 +39,22 @@ 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() reversed()
} else {
this
}
}
fun <T> List<T>.optionallyReverse(reverse: Boolean): List<T> = if (reverse) {
reversed()
} else {
this
}
fun <T> Set<T>.optionallyReverse(reverse: Boolean): Set<T> = if (reverse) {
reversed().toSet()
} else { } else {
this this
} }