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?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...it outputs:
[0 100]
[1 200]
[2 300]
=> [[0 100] [1 200] [2 300]]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
second snippet is correct, println is fine here
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 :)