Fork me on GitHub
#missionary
<
2023-08-06
>
joshcho09:08:22

This is probably a really simple question, but I can't quite figure it out after reading the docs. How do you transform a flow so that an effect is run on every new value (e.g. print on every new value), but it retains the original values?

leonoel09:08:09

here is one way (m/sample #(doto % effect!) flow)

❤️ 2
leonoel09:08:49

m/latest works too, but only in continuous time and doesn't re-run on duplicates

joshcho09:08:38

Gotcha. Would eduction be the list version of sample?

leonoel09:08:59

what do you mean ?

joshcho09:08:43

I think I understand, but essentially I was asking if the sample does the transform on each discrete value of flow, whereas eduction transforms the entire flow.

leonoel09:08:15

(m/eduction (map #(doto % effect!)) flow) also works and is semantically equivalent, transforming each discrete value of the flow. The only difference with m/sample is that m/eduction has an internal buffer, which could matter if you need to fine-tune the timing of effects

👍 2