diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/IterableExtensions.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/IterableExtensions.kt index 1ec7ced0b3b..f31e5b1c3ea 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/IterableExtensions.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/IterableExtensions.kt @@ -39,11 +39,25 @@ fun Set.paginate(with: Pagination): PaginationResult { ) } -fun Iterable.optionallyReverse(reverse: Boolean) = if (reverse) { +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) {