For some reason I can't do this in my project ```v...
# coroutines
j
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
It looks like you are lacking imports at the top of your file?
j
@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
Seems like build cache or configuration issue. Try cleaning and rebuilding the project
j
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
Try deleting .gradle folder in your project root. It has solved some issues for me in the past
j
Solved. Thanks all!