Fork me on GitHub
#missionary
<
2023-08-26
>
timur06:08:35

Hi all. If I want to make a discreet flow (via m/ap) of successive values say, taken from mailbox, is this the way to go?

(m/ap
  (let [_ (m/?> (m/seed (cycle [:i-am-a-dummy-value])))
        v (m/? mailbox)]
    v))
I haven't found anything simpler than forking on an infinite "helper" flow, and this looks pretty bad to me, as if I am missing some important piece.

leonoel07:08:39

It is one way, you can reduce it to (m/ap (m/? (m/?> (m/seed (repeat mailbox))))) Alternatively, you can use amb in a loop, which is equivalent :

(m/ap
  (loop []
    (m/amb
      (m/? mailbox)
      (recur))))

❤️ 2
timur08:08:05

@U053XQP4S, thanks! Oh wow, that nested (recur) as a parameter to m/amb has caught me off-guard. So, basically, m/amb does not actually "return" multiple values into the generated flow, it "forks" into multiple execution paths, each of which might "generate" values by itself — do I get it right?

leonoel09:08:44

yes, but it is also correct that it returns multiple values

👍 2