kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

Remove @FlowPreview on `(() ->T).asFlow()` and `(suspend () -> T).asFlow()`

Open hoc081098 opened this issue 3 years ago • 5 comments

I notice @FlowPreview has been removed on all extensions ###.asFlow() except () -> T and suspend () -> T. Can we remove it on them?

hoc081098 avatar Dec 17 '21 16:12 hoc081098

We can gradually promote them to experimental.

Our original concern was top-level scope pollution, but it seems like it doesn't bother anyone.

Could you please elaborate on your usages of these extensions?

qwwdfsad avatar Dec 21 '21 10:12 qwwdfsad

We can gradually promote them to experimental.

Our original concern was top-level scope pollution, but it seems like it doesn't bother anyone.

What does this answer mean? Can we remove FlowPreview?

martymiller avatar Jul 05 '22 16:07 martymiller

Can v1.7 remove it?

hoc081098 avatar Jul 11 '22 18:07 hoc081098

Yeah, can we remove it?

ryanholden8 avatar Jul 27 '22 14:07 ryanholden8

Just wanted to share that I added this to my app level build.gradle.kts (inside of android { })

  tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
    kotlinOptions.freeCompilerArgs += listOf(
      "-Xopt-in=kotlin.RequiresOptIn",
      "-Xopt-in=kotlin.OptIn",
      "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
      "-Xopt-in=kotlinx.coroutines.ObsoleteCoroutinesApi",
      "-Xopt-in=kotlinx.coroutines.FlowPreview"
    )
  }

This allowed me to remove all the annotations in my code without any complaints or warnings from the IDE. When FlowPreview is eventually removed, I can just remove it from here.

martymiller avatar Jul 27 '22 20:07 martymiller

It's not clear to me, without the compiler flags... can/should it be removed?

albertocavalcante avatar Nov 14 '22 10:11 albertocavalcante

Can someone write some motivation to remove @FlowPreview? What is the use case?

fvasco avatar Dec 01 '22 20:12 fvasco

With annotations like @FlowPreview you actually need to make a justification in the reverse. What is the reason to continue preventing this API from being stable? Ideally every API annotated with it would be revisited at a regular cadence to ensure that each one needs to remain unstable for some valid reason.

JakeWharton avatar Dec 01 '22 20:12 JakeWharton

It is useful to convert a lambda to Flow, without flow { emit(...) }`.

suspend fun fetchApi(): Response

fetcherFlow
  .flatMapLatest { ::fetchApi.asFlow() }
  .collect { ... }

hoc081098 avatar Dec 02 '22 03:12 hoc081098

It is useful to convert a lambda to Flow, without flow { emit(...) }`.

suspend fun fetchApi(): Response

fetcherFlow
  .flatMapLatest { ::fetchApi.asFlow() }
  .collect { ... }

For this particular snippet, I'd argue that you can use mapLatest which accepts a suspend lambda rather than converting the suspend lambda into a one-shot Flow. 🤷‍♂️

mhernand40 avatar Dec 02 '22 08:12 mhernand40

@mhernand40 of course, since it is a simple demo. When we use flatMapXXX, we usually transform the input flow to another flow...

suspend fun fetchApi(): Response

fetcherFlow
  .flatMapLatest {
    ::fetchApi.asFlow()
      .map { LCE.Success(it) }
      .onStart { emit(LCE.Loading) }
      .catch { emit(LCE.Error(it)) }
  }
  .collect { ... }

hoc081098 avatar Dec 02 '22 09:12 hoc081098