Created
April 12, 2019 15:05
-
-
Save mayojava/793daefa08d800c4eefe0f466e54ec37 to your computer and use it in GitHub Desktop.
What a mergeWith Flow operator might look like
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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