Fork me on GitHub
#missionary
<
2021-07-26
>
martinklepsch16:07:13

I have yet another question ๐Ÿ™‚ Having a flow , Iโ€™d like to reduce it (e.g. with + ) and then call a function whenever the reduced flow emitted a new value (or maybe even only if the resulting reduced value changed)

leonoel16:07:32

reductions ?

martinklepsch16:07:53

@leonoel yeah that looks promising. reductions also returns a flow does it? How would I consume each item from the flow with a callback function or similar? And could I somehow filter reductions that donโ€™t yield new/different values? (e.g. + 0)

leonoel16:07:23

it returns a flow and you may e.g pass it to eduction with dedupe

leonoel16:07:34

the callback function can be called in a map or anywhere really

leonoel16:07:52

if the business logic is really hairy, you could also consider writing a custom transducer

martinklepsch16:07:37

Gotcha, eduction + dedupe makes sense

martinklepsch17:07:00

And as to map โ€” I would then use eduction with map to trigger the side effect?

martinklepsch17:07:01

Cool. Feels a little strange to do side effects inside map but I guess I can get used to that ๐Ÿ˜„

leonoel19:07:36

in general, user-provided functions are side-effect friendly (`relieve` is the only exception, it can retry). I don't quite follow the cult of purity prevailing in the statically typed FP world ๐Ÿ™‚