I have issue in splitting seqs on a flow: ; RAW (def raw-order-flow (m/seed '([1 2 3] [4 5]))) (m/? (m/reduce conj raw-order-flow)) ; helper fn (defn split-seq-flow [s] (m/ap (loop [s s] (m/amb (first s) (let [s (rest s)] (when (seq s) (recur s))))))) (def order-flow (m/ap (let [data (m/?> raw-order-flow)] (m/?> (split-seq-flow data))))) (m/? (m/reduce conj order-flow)) ;; => [1 2 3 nil 4 5 nil] There should no be any nil There. I want the Output to be [1 2 3 4 5]. Whatever I do with amb .. either I get nothing back or it add the last recursion which produces nil.
with m/eduction and a transducer
(m/? (m/reduce conj (m/eduction cat (m/seed [[1 2 3] [4 5]]))))trying to code eduction cat behavior
(defn concat* [coll-flow]
(m/ap
(when-let [coll (m/?> coll-flow)]
(loop [coll coll]
(if (seq coll)
(m/amb (first coll) (recur (rest coll)))
(m/amb))))))
;; works with empty seq & nil values
(m/? (m/reduce conj
(concat* (m/seed [[1 2] [] [4] [nil] [5]]))))
;; res: [1 2 4 nil 5]@kawas thanks! Your concat* fn also loop-recurs. So the way how it us written must be another answer. I tried something like that.. but either got no outgoing data pushed. Or I would get a compile exception saying in ap recur needs to be the last form.
If you do not recur, then β(when β¦)β returns nil. And you get (amb (first s) nil). but what you need is a (amb) without any arguments if rest is nil. (amb) wonβt produce any value. You need something like this: (if (seq s) (amb ( first s) (recur (rest s))) (amb)) Sorry for bad formatting, I am on mobile