(chan 0) is not actually valid (should just be (chan)) - I have a ticket to
error on this more visibly.
http://dev.clojure.org/jira/browse/ASYNC-143
Trasducers may produce more than one value (per things like the mapcat
transducer) and thus a buffer is required so that there is somewhere to put
those values when they are produced. This is mentioned in the docstring for
chan:
http://clojure.github.io/core.async/#clojure.core.async/chan
"If a transducer is supplied a buffer must be specified."
On Sunday, May 15, 2016 at 4:56:03 AM UTC-5, JvJ wrote:
>
>
> 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 ( (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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.