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

julian

07/14/2020, 8:01 PM
For some reason I can't do this in my project
Copy code
val f: Flow<Int> = flow<Int> { emit(1) }.transform<Int, Int> { emit(it) }
When I compile, I get
Copy code
Error:(6, 32) Kotlin: Unresolved reference: transform
Error:(10, 47) Kotlin: Unresolved reference: transform
Error:(10, 69) Kotlin: Unresolved reference: emit
Error:(10, 74) Kotlin: Unresolved reference: it
So I set up a new project with the same dependency on
kotlinx-coroutines-core:1.3.7
. That works fine. Also, oddly, all my other flow-related code that doesn't use
transform
is fine. Has anyone else encountered this before?
d

Dico

07/14/2020, 11:10 PM
It looks like you are lacking imports at the top of your file?
j

julian

07/14/2020, 11:25 PM
@Dico Yeah, no missing imports.
Copy code
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.transform

@FlowPreview
@ExperimentalCoroutinesApi
fun main() {
    val f4: Flow<Int> = flow<Int> { emit(1) }.transform<Int, Int> { emit(it) }
}
In fact the IDE shows no errors. Errors only show in the build output log when I try to build or run.
m

Mayank

07/15/2020, 6:17 AM
Seems like build cache or configuration issue. Try cleaning and rebuilding the project
j

julian

07/15/2020, 9:33 PM
No luck. I tried deleting the build folder, cleaning and rebuilding, invalidating cache and restarting and rebuilding, and deleting the kotlinx libraries from
.gradle/caches
.
m

Mayank

07/16/2020, 7:11 AM
Try deleting .gradle folder in your project root. It has solved some issues for me in the past
j

julian

07/17/2020, 8:29 PM
Solved. Thanks all!
6 Views