missionary

2024-12-19T16:12:14.329069Z

Hi, so I’ve been playing around with missionary and it’s really an amazing library. I’m trying to only run (m/reduce) when a value changes. I.e is not equal to it’s previous value. Is there a way to do this? Here’s a rough outline of my code:

(def main
    (let [
Basically, I only want to run the m/reduce if the <result signal value is not equal to the previous <result signal value. Hope that makes sense! Thanks.

leonoel 2024-12-19T16:18:07.231239Z

cp and latest have this optimization baked in - e.g. (m/latest prn <result) will not print duplicates

leonoel 2024-12-19T16:18:44.056669Z

you still need m/reduce to sample, but it can be a no-op

2024-12-19T16:23:43.214299Z

(def main
    (let [<result (m/signal (m/latest some-query <db))
          <x (m/latest prn <result)]
      (m/reduce {} nil <x)))
So this? It looks like it works. 🤯

leonoel 2024-12-19T16:24:02.498619Z

it should

2024-12-19T16:25:43.680419Z

This is so much better than async/event buses. Blown away with how simple it has been to get the actual behaviour I want (once you get over the initial learning curve). Makes writing push based system so much nicer. Thank you!

🖤 1