Are there situations in which you, instead of usin...
# coroutines
l
Are there situations in which you, instead of using a suspend function, use a regular function that returns a Flow that emits a single value? Maybe to use some flow operators that make the code a bit cleaner?
r
It’s bad practice to create APIs based on how you assume they’ll always be used and a flow that emits exactly once is a confusing API
If the consumer decides it’s more convenient to work with flow it’s pretty simple for them to convert:
Copy code
flow {
emit(suspendingFun())
}
s
Even simpler,
(suspend () -> T).asFlow()
is in the coroutines stdlib so you can write
Copy code
::suspendingFun.asFlow()
r
My favourite thing about kotlin is that you learn a new extension function everyday 😅