Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlowCollector.emitAll #1094

Closed
fvasco opened this issue Apr 14, 2019 · 1 comment
Closed

FlowCollector.emitAll #1094

fvasco opened this issue Apr 14, 2019 · 1 comment
Labels

Comments

@fvasco
Copy link
Contributor

fvasco commented Apr 14, 2019

This is a trivial extension with the only focus on readability.
I tried to implement a trivial plus (a.k.a. concat) operator:

operator fun <T> Flow<T>.plus(other: Flow<T>): Flow<T> = flow {
    this@plus.collect(this)
    other.collect(this)
}

Is emitAll more readable?

operator fun <T> Flow<T>.plus(other: Flow<T>): Flow<T> = flow {
    emitAll(this@plus)
    emitAll(other)
}

public suspend inline fun <T> FlowCollector<T>.emitAll(other: Flow<T>) {
    other.collect(this)
}

public suspend inline fun <T> FlowCollector<T>.emitAll(values: Iterable<T>) {
    for (value in values) emit(value)
}
@qwwdfsad qwwdfsad added the flow label Apr 15, 2019
@fvasco
Copy link
Contributor Author

fvasco commented May 2, 2019

Use case #1168

qwwdfsad added a commit that referenced this issue May 29, 2019
qwwdfsad added a commit that referenced this issue Jun 5, 2019
qwwdfsad added a commit that referenced this issue Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants