missionary

braai engineer 2025-03-30T11:32:30.343569Z

Learning Missionary by doing silly things: I have a sleepy-sort based on the docs, where given a collection of delays, (m/sleep delay delay), it should zip the delayed values up into a vector that represents order (using (m/seed (range))) and println the [idx delay] as they arrive , e.g. expected:

(sleepy-sort [200 100 300])
[0 100]
[1 200]
[2 300]
=> [[0 100] [1 200] [2 300]]
But Missionary says "Execution error (ClassCastException) at missionary.impl.Zip/run. If I take out the m/?> in (let [pair (m/?> ...) I see the correct "delayed behaviour" but with function pairs instead of values, obviously because I'm not doing something like m/? on the zipped flow. The m/zip makes sense to me: join these two flows via vector, fork via m/?> so it should println whenever a pair is ready. What am I misunderstanding about forking flows?

braai engineer 2025-03-30T11:52:53.956859Z

Ok, so this does what I want based on docs:

(->> (m/zip vector
            (m/seed (range))
            (m/ap (let [n (m/?> ##Inf (m/seed [300 100 200]))]
                    (m/? (m/sleep n n)))))
     (m/reduce (fn [acc e]
                 (println e)
                 (conj acc e))
               [])
     (m/?))
awesome. not sure if putting the println in the m/reduce is the right place tho...

braai engineer 2025-03-30T11:53:06.464919Z

it outputs:

[0 100]
[1 200]
[2 300]
=> [[0 100] [1 200] [2 300]]

leonoel 2025-03-30T16:16:26.102709Z

The type mismatch in the first snippet is m/zip expecting a flow as third argument but (let [n (m/?> ##Inf flow)] (m/? (m/sleep n n))) is the type of n i.e. number

👍 1
leonoel 2025-03-30T16:16:43.947749Z

second snippet is correct, println is fine here

braai engineer 2025-03-30T11:38:57.714559Z

What's the difference between m/enumerate and m/seed? It seems they both turn a collection into a discrete flow, but not obvious to me from docs when to use which. Edit: Ah I was looking at old Docs. I see they are the same thing :)