fun constructFlow() = flow { for(x in channel) emit(x) }
Is there any practical difference between
Copy code
val someFlow = constructFlow()
and
Copy code
val someFlow get() = constructFlow()
?
I do realize, that second version will call constructFlow on every access, while first one - only once. But since a flow is only a definition of what should happen after collection - isn`t it always the same?
z
Zach Klippenstein (he/him) [MOD]
11/04/2020, 8:16 AM
no practical difference, definitely no difference in behavior
e
ephemient
11/04/2020, 8:52 AM
if there's some external state like
Copy code
fun constructFlow: Flow<Int> {
var x = 0
return flow { emit(++x) }
}
then they might behave differently, but in your case it looks like it would have the same effect either way