but in the middle, the traverse wraps the whole fl...
# arrow
p
but in the middle, the traverse wraps the whole flow into an effect F
s
Not 100% sure what you mean with this?
p
let me try to simplify the code to give you the hang of it
šŸ‘ 1
Copy code
//the first fx.monad composition is only to sequence multiple effectful ops
fun <F> MonadDefer<F>.doThis() = fx.monad {
    val (manager) = ...some stuff
    later {
        manager.on<Event>().k() //<- switch to kotlin flowK
            .filter (...)
            .traverse(this@doThis) { ev ->
                //call that creates a Kind<F, A>
             }.map {
                 it.value() //<- unwraps the FlowK
                     .flatMap { result ->
                           createAction(result).asMono()
                     }.subscribe()
             }
    }.bind()
}
s
Oh right okay, I see now. You’re using
Flow
within
F
.
p
so, until I call traverse… we got a flowK, but traverse extracts some other
Kind<F, _>
that now contains the new flow
I’m currently seeing that I might be wrapping everything in a
later
that gets
bind()
-ed, but I might’ve forgotten to do the same with the ā€œwrappedā€ effect?
s
You’re here basically reacting to events that you get from
manager
, right?
So you’re not interested in exposing that stream since you return
F
instead?
Btw are we talking about
Flow
or
Flux
? If there is an integration package for
Flow
we’d love to have it in Arrow.
Also if you’re interested in porting the RxJava Concurrent instances to Reactor that’d be cool šŸ˜„ I’d love to help you out with anything
p
Sorry, my bad, it’s
FluxK
I get confused easily with reactor’s terminology, not used to it
šŸ‘ 1
this is a really ā€œsideā€ project
I don’t work enough on kotlin to invest so much on it now, I’m sorry šŸ˜…
s
No problem šŸ™‚
p
I didn’t get your meaning about not being interested in the stream (I think you’re referring to the reactive flow here, right?)
I have this flow of events and I need to respond via messaging as a mono event
s
Yes, what is the return type of that function?
p
with the added complexity that my internal response depends on a wrapped effect value
s
Let me whip up something of what I think could work for you
p
so if I simply subscribe, the internal effect wouldn’t be evaluated, so I’ve tried to do the traversal to get it out and compose it with other effects
to give you more info, I’m trying to integrate arrow with this discord reactive integration: https://github.com/MinnDevelopment/jda-reactor#reactiveeventmanager
you can see the example code there…
s
This is a small example that wraps the stream of
Events
from the manager, and executes an effect
F
for every
Event
. This
doThis(): Kind<F, Unit>
finishes when all events are processed.
I included all imports and the mocks I used to make the types align šŸ™‚
p
Thank you so much @simon.vergauwen, I’ll definitely look into that
šŸ‘ 1
I’ll let you know
@simon.vergauwen I’m missing one thing, what does the
!
prepended to the
manager.onEvent...
at line 27 does?
is the result a whole suspended effect that needs be evaluated?
s
ah you could also replace it with
val (unit) = manager.onEvent().k()
or
.bind()
at the end
The result of the last
flatMap
on
manager.onEvent().k()
returns
Unit
but you still need to execute it within
fx
with
component1
,
bind
or
not
p
nice, didn’t know that shortcut (I’ve only seen it used with
effect{...}
in examples and didn’t make the connection 😁
s
Those 3 are all aliases šŸ˜‰