Hi, I'm lookin the way to implement flow which wil...
# getting-started
k
Hi, I'm lookin the way to implement flow which will emit values according to input parameter known when collect is call. Let's say that I have some operation
(P)->R
and I want to use flow api to handle it. I can't create flow standard way through flow builder because parameter P is not known at this point. Is there a way to achieve result similar to this:
Copy code
fun Flow<R>.asLambda(operation: (P)->R): (P)->Unit = {
    // some magic that allow me to use P parameter to modify existing flow emission
    collect()
}
s
Copy code
fun <P, R> Flow<R>.asLambda(operation: (P) -> R): (P) -> Unit = {
  operation(it)
  ...
}
d
Hmm, why not
Copy code
fun makeFlow(parameter: P) = flow { 
    val r = operator(P)
k
I don't have parameter at the moment of flow creation. That's the point, I'm not even sure is effect I want to achieve in possible, since flow immutability principle
d
My suggestion is to not create the flow until you do have the parameter.
k
I can't use flow api then, which was the main goal, mission failed 😕
d
It's a lot like the Sequence API. If you think of it that way, you'd probably be better able to make use of it.