https://kotlinlang.org logo
Title
n

Nikky

01/19/2021, 5:42 PM
how to i take the first element fro ma flow and then consume the rest with collect ? seems like when i use
take
it closes the flow
l

louiscad

01/19/2021, 5:43 PM
withIndex + collect and destructuring
n

Nikky

01/19/2021, 5:44 PM
ohh, smart
that is a bit akward because i want to get the login info from the first websocket frame and need to then use the security context for the rest of the code
l

louiscad

01/19/2021, 5:47 PM
If you have a better idea about the API you want, I guess it's relatively easy to implement it yourself
n

Nikky

01/19/2021, 6:02 PM
how can i implement taking one value out a flow without cancelling it ? that seems to be the main issue.. and that spring + reactor types are involved possibly
l

louiscad

01/19/2021, 6:02 PM
By using
collect
collect
is the base of every flow operator
You can also use
shareIn
or
stateIn
n

Nikky

01/19/2021, 6:06 PM
when i use shareIn i can then call
first()
and
.skip(1).collect()
later correct ? or do i need to ensure it has a buffer for that ?
l

louiscad

01/19/2021, 6:07 PM
It depends on the timing, but probably
n

Nikky

01/19/2021, 6:08 PM
the first message should be there instantly.. the other ones could come later.. i will jsut try this
this seemed to have worked, thx
👍 1
d

Dominaezzz

01/19/2021, 8:32 PM
Could always
produceIn
and
receive()
the items manually.
👍 1
l

louiscad

01/19/2021, 8:35 PM
Ah yes, very true, you can do something like that:
yourFlow.produceIn(someScope).consume {
    receive() // First value
    receiveAsFlow().collect { // Other values
    }
}