sorting a kotlin list but with conditionals

hello, i am having some kotlin trouble on how to code this thing. basically, i want to sort the userList if wins/loss is not infinite and sort it by wins if it is infinite. but it seems its not so intuitive to do that with my approach because the function seems to not accept conditionals override fun getItemCount(): Int { userList = userList.sortedByDescending{ var num = (it.wins.toFloat()/it.losses.toFloat()) if(!(num.isInfinite())){ it.wins.toFloat()/it.losses.toFloat() } else{ it.wins } } return userList.size } error i get is type parameter bound for R in inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T> is not satisfied: inferred type Any is not a subtype of Comparable<Any>

submitted by /u/lasagna_lee
[link] [comments]