There is snipt code in my Kotlin code:
val dataMap = sensoryDataUsage.groupBy { it } .mapValues { it.value.count().toDouble()/count } .mapKeys { println(it.key); it.key.toDouble()/max } .toSortedMap(object : Comparator<Double> { override fun compare(p0: Double, p1: Double): Int { return (p1-p0).compareTo(0) } })
Everything went perfectly. However, the IDE continues to offer me to convert this Comparator object to lambda, and I did just that:
val dataMap = sensoryDataUsage.groupBy { it } .mapValues { it.value.count().toDouble()/count } .mapKeys { println(it.key); it.key.toDouble()/max } .toSortedMap {x, y -> (yx).compareTo(0)}
This job. However, it cannot be compiled:
Error:(32, 14) Kotlin: Type inference failed: fun <K, V> Map<out K, V>.toSortedMap(comparator: Comparator<in K>): SortedMap<K, V> cannot be applied to receiver: Map<Double, Double> arguments: ((Double, Double) -> Int)
Any ideas what went wrong? Thanks in advance.
source share