Last active
March 17, 2021 13:14
-
-
Save ramiloif/0011fa7c0c1538a7ee770375007c2873 to your computer and use it in GitHub Desktop.
reduce in Kotlin Flow sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun main(args: Array<String>) { | |
sample(flowOf(1, 2, 3)) | |
} | |
suspend fun sample(numbers: Flow<Int>): Int { | |
return numbers.reduce { acc, value -> | |
acc + value | |
} | |
} | |
// prints 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment