I don't have much experience with core.async, and I recently tried using
channels with transducers. Strangely, I found that you need a buffer with
a size
of at least one in order for the transducer to be applied.
I have a few toy functions:
(defn push-nums
"Push a few numbers on a channel."
[n c]
(go (loop [i 0]
(when (< i n)
(>! c i)
(recur (inc i))))
(>! c :end)))
(defn print-nums
"Take the numbers from the channel and print them."
[c]
(go
(loop []
(let [n (<! c)]
(when (not= :end n)
(println "A num: " n)
(recur))))
(println "Finished with nums!!")))
I used them in two different scenarios:
(let [c (chan 0 (map inc))] (push-nums 5 c) (print-nums c))
;=> A num: 0
;=> A num: 1
;=> A num: 2
;=> A num: 3
;=> A num: 4
;=> Finished with nums!!
(let [c (chan 1 (map inc))] (push-nums 5 c) (print-nums c))
;=> A num: 1
;=> A num: 2
;=> A num: 3
;=> A num: 4
;=> A num: 5
The transducer only gets applied when the argument 1 is passed in. I
assume this is by design, but I don't like the fact that
using transducers effectively limits certain options with channels.
Does anyone know if there's a type of buffer that can be used to get around
this?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.