Skip to content

Instantly share code, notes, and snippets.

@ramiloif
Last active March 17, 2021 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramiloif/0011fa7c0c1538a7ee770375007c2873 to your computer and use it in GitHub Desktop.
Save ramiloif/0011fa7c0c1538a7ee770375007c2873 to your computer and use it in GitHub Desktop.
reduce in Kotlin Flow sample
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