I wrote (copied) extension function `Iterable<T>.s...
# compose
l
I wrote (copied) extension function
Iterable<T>.sumOf(selector: (T) -> Dp): Dp
but for some reason compiler want to use it even for other types like Int and Double. I added annotation
OverloadResolutionByLambdaReturnType
that if I got it right should alter preference, but it doesn't.
Copy code
@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@JvmName("sumOfDp")
inline fun <T> Iterable<T>.sumOf(selector: (T) -> Dp): Dp {
    var sum: Dp = 0.dp
    for (element in this) {
        sum += selector(element)
    }
    return sum
}
I know that I can just sum Dp.value.toDouble() but I want to know where the problem is
e
add
Copy code
import kotlin.collections.sumOf
so that both the default sumOf and your sumOf are considered
🙌 2