https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

Tash

06/04/2020, 11:01 PM
Hi everyone, curious about everyone’s preferred nomenclature for methods returning
Flow<T>
For example:
Copy code
// For Flow<List<*>>
fun postsFlow(): Flow<List<Post>> 
// OR
fun postLists(): Flow<List<Post>>


// For Flow<*>
fun eventFlow(): Flow<Event>
// OR
fun events(): Flow<Event>
Would be interesting to know if there are other preferred styles.
👀 1
r

Ray Ryan

06/04/2020, 11:05 PM
I like the latter in both cases.
👍🏼 2
☝️ 1
Just
postList()
for the first one, if it’s a property that changes on occasion.
h

henrikhorbovyi

06/04/2020, 11:51 PM
second option for both \o/
👍🏼 1
o

Orhan Tozan

06/08/2020, 8:21 AM
posts() and events()
e

elizarov

06/08/2020, 8:50 AM
It might look even better as a property. Flows are cold, nothing happens when you “call” these functions, so there’s no need to write
events()
. Those
()
do not signify anything. Just writing
events
should do just as well.
👍 2
t

Tash

06/08/2020, 8:04 PM
Nice, makes sense that they can just be `val`s if no arguments are needed.
o

Orhan Tozan

06/09/2020, 8:32 PM
@Tash just because not having arguments isnt a sufficient reason for going for a property over a method. If a method has side effects, you better keep it as a method, even if it requires no arguments
t

Tash

06/09/2020, 8:38 PM
For sure, this is more about:
Copy code
fun events() = flow<Event> {
   ...
}

VS

val events = flow<Event> {
   ...
}
And not about the case where
events()
causes side-effects etc.
l

louiscad

06/09/2020, 9:01 PM
@Orhan Tozan If you use
flow { }
builder, there's not really any side effects, that's why it's perfectly safe to keep it in a property.
4 Views