Skip to content

Instantly share code, notes, and snippets.

@NoNews

NoNews/Flow.kt Secret

Created January 3, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoNews/1d62914a597a18934a53d453f4e7bb6b to your computer and use it in GitHub Desktop.
Save NoNews/1d62914a597a18934a53d453f4e7bb6b to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.flow.internal.unsafeFlow as flow
public fun <T> flowOf(value: T): Flow<T> = flow {
emit(value)
}
internal inline fun <T> unsafeFlow(crossinline block: suspend FlowCollector<T>.() -> Unit): Flow<T> {
return object : Flow<T> {
override suspend fun collect(collector: FlowCollector<T>) {
collector.block()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment