sum

suspend fun Flow<Byte>.sum(): Long

Sums the elements of this Flow of Byte and returns the result.

Return

The sum of all elements emitted by the source Flow.

Example usage:

val flow = flowOf(1, 2, 3, 4, 5).map { it.toByte() }
val sum = runBlocking { flow.sum() }
println(sum) // prints: 15

suspend fun Flow<Double>.sum(): Double

Sums the elements of this Flow of Double and returns the result.

Return

The sum of all elements emitted by the source Flow.

Example usage:

val flow = flowOf(1.0, 2.0, 3.0, 4.0, 5.0)
val sum = runBlocking { flow.sum() }
println(sum) // prints: 15.0

suspend fun Flow<Float>.sum(): Double

Sums the elements of this Flow of Float and returns the result.

Return

The sum of all elements emitted by the source Flow.

Example usage:

val flow = flowOf(1.0, 2.0, 3.0, 4.0, 5.0)
val sum = runBlocking { flow.sum() }
println(sum) // prints: 15.0

suspend fun Flow<Int>.sum(): Long

Sums the elements of this Flow of Int and returns the result.

Return

The sum of all elements emitted by the source Flow.

Example usage:

val flow = flowOf(1, 2, 3, 4, 5)
val sum = runBlocking { flow.sum() }
println(sum) // prints: 15

suspend fun Flow<Long>.sum(): Long

Sums the elements of this Flow of Long and returns the result.

Return

The sum of all elements emitted by the source Flow.

Example usage:

val flow = flowOf(1L, 2L, 3L, 4L, 5L)
val sum = runBlocking { flow.sum() }
println(sum) // prints: 15

suspend fun Flow<Short>.sum(): Long

Sums the elements of this Flow of Short and returns the result.

Return

The sum of all elements emitted by the source Flow.

Example usage:

val flow = flowOf(1, 2, 3, 4, 5).map { it.toShort() }
val sum = runBlocking { flow.sum() }
println(sum) // prints: 15