Is there some nifty way to get the last emitted va...
# flow
e
Is there some nifty way to get the last emitted value of a flow, without having to cache it my self?
v
Consider using StateFlow ?
I mean, if you look at Flow itself - it could be represented as an abstraction around a process of subscribing to event listener, getting some events (with possibity of generating side to inform that there won't be events anymore) and unsubscribe at any moment. If you want an ability to get the latest event - you can write your code that caches the event (that's what you propose) or include this ability to event sender's contract (StateFlow).
e
I’ve not looked into StateFlow yet, but from what I’ve seen it might be what I’m after. Not sure it’s available in the kotlin version we’re currently are using, but I’m gonna have a look 🙂
a
fun <T> Flow<T>.conflate(): Flow<T>
might help.