New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zipWithNext for Flow #1767
Comments
Implementation is pretty straight-forward, but what's your use-case? Why do you need it?
|
Thanks for helping out @elizarov Well is not something that can't be done differently. I'm new to Coroutines but I am building a bluetooth library on Android using Coroutines/Flow. As such during the readout response, which btw happens byte-by-byte via Flow, I need to check whether a specific pair of Hex bytes (02 FF) is included in the response when eventually collecting those bytes. But I came up with an alternative using buffers and accumulating the whole Bluetooth Response into a ByteArray before it's collected by Flow. So in that case |
Good that you've found a better way. |
I would've found this useful for diffing upstream values into downstream change events. datasets // DataSet1… DataSet2… DataSet3… DataSet… DataSet…
.onStart { emit(DataSet.empty) } // DataSet.empty… DataSet1… DataSet2… DataSet3… DataSet… DataSet…
.zipWithNext { a, b -> b.changesSince(a) } // [Change1a, Change1b, Change1c]… [Change2a, Change2b]…
.flatMapConcat { changes -> changes.asFlow() } // Change1a… Change1b… Change1c… Change2a… Change2b… |
@fluidsonic Thanks for a use-case. |
@elizarov Should it be added to core? I currently need to merge the values of each emission, or is there a better way? |
@rinorz You can use this implementation for now -> #1767 (comment) |
Yes, I am currently doing this, I mean it might be added to the coroutine core, maybe it is useful |
Another use case: differentiating between existing state and between state changes. For example, we have We are using a bit modified version of the above implementation, where |
Can we have a
zipWithNext
operator for Flow? Could you help me implement one?The text was updated successfully, but these errors were encountered: