You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have several cases where I need to group flow events by time and then combine them into something. The simplest example is averaging. If I have the real-time data, I frequently want to take all points in a given time window and return only averaged value for this time frame (or default value if no events happened in this time window). I have several such cases in VisionForge (visualization library) and Controls-kt (device data acquisition.
The Shape of the API
I would call it sample, but it is already taken, so it could be something like chunkedByTime to be aligned with stdlib method for collections. So, it could look like this: fun Flow<T>.chunkedByTime(duration: Duration): Flow<List<T>.
To make the API more universal one could provide external signal trigger. So, the collection is triggered by obtaining signal from a flow or channel.
Another API consideration is usage of API on numbers. For my purposes List is OK, it could be grouped later, which gives flexibility. But when we use List of numbers, it impacts performance. So, one could provide an inline method that transforms array of numbers internally in the flow evaluation loop. Like fun Flow<Double>.chunkedDoubleByTime(duration: Duration, collector: (DoubleArray)->R): Flow<Double>. Such API is opinionated, so I am not sure it should be in the library.
Prior Art
sample and debounce has similar functionality, but they return only one value, not all of them. I think the implementation could share some code.
The text was updated successfully, but these errors were encountered:
Sure, it could be useful. Could you please add your use case under that issue?
Closing this issue, as we'd like to keep all pieces of the discussion centralized, so that we don't have to gather the information from all around the issue tracker.
Use case
I have several cases where I need to group flow events by time and then combine them into something. The simplest example is averaging. If I have the real-time data, I frequently want to take all points in a given time window and return only averaged value for this time frame (or default value if no events happened in this time window). I have several such cases in VisionForge (visualization library) and Controls-kt (device data acquisition.
The Shape of the API
I would call it
sample
, but it is already taken, so it could be something likechunkedByTime
to be aligned with stdlib method for collections. So, it could look like this:fun Flow<T>.chunkedByTime(duration: Duration): Flow<List<T>
.To make the API more universal one could provide external signal trigger. So, the collection is triggered by obtaining signal from a flow or channel.
Another API consideration is usage of API on numbers. For my purposes List is OK, it could be grouped later, which gives flexibility. But when we use List of numbers, it impacts performance. So, one could provide an inline method that transforms array of numbers internally in the flow evaluation loop. Like
fun Flow<Double>.chunkedDoubleByTime(duration: Duration, collector: (DoubleArray)->R): Flow<Double>
. Such API is opinionated, so I am not sure it should be in the library.Prior Art
sample
anddebounce
has similar functionality, but they return only one value, not all of them. I think the implementation could share some code.The text was updated successfully, but these errors were encountered: