Fork me on GitHub
#missionary
<
2022-07-21
>
reedho10:07:10

(m/? (m/reduce
       conj
       (m/ap (let [x (m/?> (m/seed [1 2 3 4 5]))]
               (if (= 2 x)
                 (m/?> m/none)
                 x)))))
;; => [1 3 4 5]

reedho10:07:06

How to stop the flow at 2, e.g. expected return value is [1]

leonoel10:07:20

m/eduction + take-while

reedho10:07:18

Thank you, let me try

reedho10:07:04

(m/? (m/reduce
       conj
       (m/ap (let [x (m/?> (m/eduction (take-while #(< % 2))
                                       (m/seed [1 2 3 4 5])))]
               x))))

reedho10:07:09

In case that i'm working with unbound flow, e.g. some thing from (m/observe ..) or (m/watch ..), how to signal for the flow to done ?

leonoel10:07:22

do you mean termination signaled by the producer not the consumer ?

reedho10:07:38

((m/reduce (fn [_ x]
                 (prn "X" x))
               nil
               (m/ap
                 (m/?> m/none)
                 (let [x (m/?> (m/watch _atom1))]
                       (if (= 5 x)
                         (m/?> m/none)
                         x)))
               )
     #(prn "done" %)
     #(prn "fail" %))

leonoel10:07:09

what is this example showing ?

reedho10:07:00

I expect when the _atom1 value goes to 5, the flow would stop ("done" printed)

reedho10:07:40

((m/reduce (fn [_ x]
                 (prn "X" x))
               nil
               (m/ap
                 (let [x (m/?> (m/watch _atom1))]
                       (if (= 5 x)
                         (m/?> m/none)
                         x)))
               )
     #(prn "done" %)
     #(prn "fail" %))
This is the correct one, sorry

reedho10:07:27

I mean that is the correct example, the previous one is not correct on line 5

leonoel10:07:51

use eduction, same as before ?

reedho10:07:56

Yes, that's should work,.. but probably my real question is there a way to signal termination from the inside, e.g. in case we use (m/observe ..) we want to stop based on specific event value

reedho10:07:05

Sorry for my bad english 🙂

leonoel10:07:50

you mean the stream of values produced by the subject is finite ?

reedho10:07:29

Yes, probably so.. e.g. the subject will tell that there is no more values by now, so make the main task be finished cleanly

leonoel10:07:43

it is not supported yet, but if you have a compelling use case I'll consider it

leonoel10:07:29

as a workaround you can emit a sentinel value

reedho10:07:21

I see.. so using eduction + take-while is the way to go for now, correct?

reedho10:07:27

Ok, many thanks

reedho12:07:03

I put minimum demo while on the go here 🙏