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

Why is fun <T> (suspend () -> T).asFlow(): Flow<T> still marked as @FlowPreview? #3542

Closed
LouisCAD opened this issue Dec 1, 2022 · 4 comments

Comments

@LouisCAD
Copy link
Contributor

LouisCAD commented Dec 1, 2022

Hello,

I just noticed the suspend function to Flow extension (fun <T> (suspend () -> T).asFlow(): Flow<T>) is still marked as @FlowPreview.
Is there a reason why?

My use case today was creating a combined flow where one of the inputs is a suspend function:

fun watchAppInstallationStatusFlow(
    capabilityClient: CapabilityClient,
    nodeClient: NodeClient,
): Flow<WatchAppInstallationStatus> {
    return combine(
        capabilityClient.watches(),
        suspend { nodeClient.connectedNodes.await() }.asFlow()
    ) { watchNodesWithApp, connectedNodes ->
        TODO()
    }
}
@LouisCAD
Copy link
Contributor Author

LouisCAD commented Dec 1, 2022

BTW, I can see the more primitive way is actually shorter, so that might be part of the answer?

  • flow { emit(nodeClient.connectedNodes.await()) }
  • suspend { nodeClient.connectedNodes.await() }.asFlow()

@hoc081098
Copy link

hoc081098 commented Dec 1, 2022

I have created #3097

@JakeWharton
Copy link
Contributor

nodeClient::connectedNodes.asFlow() beats your flow variant in code golf, not that pinching pennies in character count is a particularly interesting factor in determining final API surface.

qwwdfsad added a commit that referenced this issue Dec 7, 2022
@murligit
Copy link

override fun observeIsTyping(): Flow =
currentChatDocument?.collection("isTyping") // use collection instead of document
?.document(currentUser?.uid ?: "") // use currentUser?.uid as the document ID
?.asFlow()
?.map { snapshot: DocumentSnapshot ->
snapshot.getBoolean("isTyping") ?: false // use "isTyping" as the field name
}
?: emptyFlow()

Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun <T> (() -> TypeVariable(T)).asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow
public fun <T> Array<TypeVariable(T)>.asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow
public fun IntArray.asFlow(): Flow<Int> defined in kotlinx.coroutines.flow
public fun LongArray.asFlow(): Flow<Long> defined in kotlinx.coroutines.flow
public fun <T> Iterable<TypeVariable(T)>.asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow
public fun <T> Iterator<TypeVariable(T)>.asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow
public fun IntRange.asFlow(): Flow<Int> defined in kotlinx.coroutines.flow
public fun LongRange.asFlow(): Flow<Long> defined in kotlinx.coroutines.flow
public fun <T> Sequence<TypeVariable(T)>.asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow
public fun <T> BroadcastChannel<TypeVariable(T)>.asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow
public fun <T> (suspend () -> TypeVariable(T)).asFlow(): Flow<TypeVariable(T)> defined in kotlinx.coroutines.flow this is my issue solve it please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants