Skip to content

Instantly share code, notes, and snippets.

@mayojava
Created April 12, 2019 15:05
Show Gist options
  • Save mayojava/793daefa08d800c4eefe0f466e54ec37 to your computer and use it in GitHub Desktop.
Save mayojava/793daefa08d800c4eefe0f466e54ec37 to your computer and use it in GitHub Desktop.
What a mergeWith Flow operator might look like
@FlowPreview
fun <T> Flow<T>.mergeWith(other: Flow<T>): Flow<T> = flow {
coroutineScope {
launch {
other.collect {
emit(it)
}
}
launch {
collect {
emit(it)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment