I'm trying to take an array of Pairs(StartTime:Int, EndTime:Int) and reduce them to the accumulation of time for each session.
fun main() {
val sessionsInSecond = listOf<Pair<Int,Int>>(Pair(10,12), Pair(10,15))
val timeSpan: Int = sessionsInSecond.reduce{acc, it -> acc + (it.second - it.first) }
println(timeSpan)
}
This gives me the following error:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: @InlineOnly public inline operator fun BigDecimal.plus(other: BigDecimal): BigDecimal defined in kotlin @InlineOnly public inline operator fun BigInteger.plus(other: BigInteger): BigInteger defined in kotlin public operator fun Array.plus(elements: Array): Array defined in kotlin.collections public operator fun Array.plus(elements: Collection): Array defined in kotlin.collections public operator fun Array.plus(element: Int): Array defined in kotlin.collections public operator fun BooleanArray.plus(element: Boolean): BooleanArray defined in kotlin.collections public operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray defined in kotlin.collections public operator fun BooleanArray.plus(elements: Collection): BooleanArray defined in kotlin.collections public operator fun ByteArray.plus(element: Byte): ByteArray defined in kotlin.collections public operator fun ByteArray.plus(elements: ByteArray): ByteArray defined in kotlin.collections public operator fun ByteArray.plus(elements: Collection): ByteArray defined in kotlin.collections @InlineOnly public inline operator fun Char.plus(other: String): String defined in kotlin.text public operator fun CharArray.plus(element: Char): CharArray defined in kotlin.collections public operator fun CharArray.plus(elements: CharArray): CharArray defined in kotlin.collections public operator fun CharArray.plus(elements: Collection): CharArray defined in kotlin.collections public operator fun DoubleArray.plus(element: Double): DoubleArray defined in kotlin.collections public operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray defined in kotlin.collections public operator fun DoubleArray.plus(elements: Collection): DoubleArray defined in kotlin.collections public operator fun FloatArray.plus(element: Float): FloatArray defined in kotlin.collections public operator fun FloatArray.plus(elements: FloatArray): FloatArray defined in kotlin.collections public operator fun FloatArray.plus(elements: Collection): FloatArray defined in kotlin.collections public operator fun IntArray.plus(element: Int): IntArray defined in kotlin.collections public operator fun IntArray.plus(elements: IntArray): IntArray defined in kotlin.collections public operator fun IntArray.plus(elements: Collection): IntArray defined in kotlin.collections public operator fun LongArray.plus(element: Long): LongArray defined in kotlin.collections public operator fun LongArray.plus(elements: LongArray): LongArray defined in kotlin.collections public operator fun LongArray.plus(elements: Collection): LongArray defined in kotlin.collections public operator fun ShortArray.plus(element: Short): ShortArray defined in kotlin.collections public operator fun ShortArray.plus(elements: ShortArray): ShortArray defined in kotlin.collections public operator fun ShortArray.plus(elements: Collection): ShortArray defined in kotlin.collections public operator fun String?.plus(other: Any?): String defined in kotlin public operator fun String?.plus(other: Any?): String defined in kotlin public operator fun Collection.plus(elements: Array): List defined in kotlin.collections public operator fun Collection.plus(elements: Iterable): List defined in kotlin.collections public operator fun Collection.plus(elements: Sequence): List defined in kotlin.collections public operator fun Collection.plus(element: Int): List defined in kotlin.collections public operator fun Iterable.plus(elements: Array): List defined in kotlin.collections public operator fun Iterable.plus(elements: Iterable): List defined in kotlin.collections public operator fun Iterable.plus(elements: Sequence): List defined in kotlin.collections public operator fun Iterable.plus(element: Int): List defined in kotlin.collections public operator fun Map.plus(pairs: Array>): Map defined in kotlin.collections public operator fun Map.plus(pair: Pair): Map defined in kotlin.collections public operator fun Map.plus(pairs: Iterable>): Map defined in kotlin.collections public operator fun Map.plus(map: Map): Map defined in kotlin.collections public operator fun Map.plus(pairs: Sequence>): Map defined in kotlin.collections public operator fun Set.plus(elements: Array): Set defined in kotlin.collections public operator fun Set.plus(elements: Iterable): Set defined in kotlin.collections public operator fun Set.plus(elements: Sequence): Set defined in kotlin.collections public operator fun Set.plus(element: Int): Set defined in kotlin.collections public operator fun Sequence.plus(elements: Array): Sequence defined in kotlin.sequences public operator fun Sequence.plus(elements: Iterable): Sequence defined in kotlin.sequences public operator fun Sequence.plus(elements: Sequence): Sequence defined in kotlin.sequences public operator fun Sequence.plus(element: Int): Sequence defined in kotlin.sequences
Any suggestions how to solve this? ps. It's an exercise in reduce so i don't want to just add the values in a forEach loop.