Provide a `collectIndexed` terminal operator
See original GitHub issueHi,
Like with collections and sequences we occasionally need to iterate and maintain an index like this:
var index = 0
values.collect {
// do something with the value, knowing its index.
++index
}
Since forEachIndexed
already exists for Iterable
and Sequence
and consumeEachIndexed
exists for ReceiveChannel
it would seem natural to me that flows provide a collectIndexed
terminal operator.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
collectIndexed - Kotlin
Terminal flow operator that collects the given flow with a provided action that takes the index of an element (zero-based) and the element....
Read more >flow - GitHub Pages
Creates a cold flow from the given suspendable block. The flow being cold means that the block is called every time a terminal...
Read more >Using LiveData & Flow in MVVM — Part III - ProAndroidDev
Because Flow is providing all of the data in the same coroutine context ... We can use the collect terminal operator for starting...
Read more >A story of building a custom Flow operator - bufferTimeout
As collect is a terminal operation that will not finish until the upstream is finished, we need to put it in a coroutine,...
Read more >Terminal Operators in Kotlin Flow - Amit Shekhar
My mission is to provide tech education to the students through project-based learning to achieve the outcome they aspire to.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jcornaz When you say “we occasionally need” can you provide a slightly more concrete example where this might be needed when you work with flows, please. E.g. if you had recently run into this need in your project, you can explain what was the problem you were solving.
@jcornaz
I agree.
In escape analisys we hope