A teammate just told me he was having a problem wi...
# android
b
A teammate just told me he was having a problem with
collect { }
. His issue was that the AS was expecting him to add the
@InternalCoroutinesApi
annotation, and it also required he add in the
FlowCollector
object implementation directly. At first I didn't know what happened, until he showed me the source code of the
collect
function he was calling. Turned out it was the
collect
function from the
Flow.kt
file. I asked if he had the option to do the auto-import for the extension function
collect
, but he didn't. I tried just typing out the
collect
function out without auto-complete, and saw this happening on my machine as well. This confused my teammate who is learning Coroutines and Flows, but I'm curious if anyone else has run into this either personally or with teammates.
2
Yep, happens in IntelliJ IDEA as well...
e
the IDE does try to help you with autocomplete, https://youtrack.jetbrains.com/issue/KT-36808
b
I understand that we should not use the method
collect
, however my teammate is new to Flows, and was confused at first about why
collect
was giving him problems. He didn't use auto-complete, he just typed out the call to
collect
, which led to him calling the method instead of the extension function. The frustrating part was that he didn't know he had to import the extension function, as he never got the indication to do so after typing out the call to
collect
.
I had to tell him to add the import statement manually to fix his problem. There was no auto-import or auto-fix for this.
j
I have the same pain. I trained myself to either wait for the complete dialog to pop up and select the correct one or hit the ctrl+space after typing it and then select it to import the correct extension function
but yeah it is a conscious action you have to perform every time, which sucks
e
unfortunately both
collect
names are part of the public API and can't be changed (well,
@InternalCoroutinesApi
doesn't have stability guarantees, but it would still be a breaking change to rename it), so we'll have to live with this situation for the time being. can ask in #coroutines but I think JB has some ideas about getting rid of the
collect
method altogether, eventually.
b
I think I should move this conversation to #coroutines to at least bring appropriate attention to this. I'm already working to add this as a line item in our team's coroutines practices guide, but it really shouldn't be.