(let [out (async/chan 0 (map inc))]
(async/pipe in out)
out)
Earlier in your email you mention printing, however. If you have I/O to
perform (like printing), I’m told that you don’t want to do it in a
transducer. You can use pipeline-async for this instead:
(defn f [v ch]
(async/go
(println v)
(async/>! ch v)))
(let [out (async/chan)]
(async/pipeline-async 1 out f in)
out)
(If I’m doing this wrong, someone please steer me in the right direction.)
e
On Wed, Feb 18, 2015 at 4:47 PM, Ben Smith-Mannschott <[email protected]>
wrote:
I'm probably just especially dense today, but perhaps someone can give me a
> poke in the right direction.
>
> I'm trying to wrap my head around transducers.
>
> (1) For debugging purposes I'd like to be able to consume the values on a
> channel and put them in a collection to be printed.
>
> I'm doing this at the REPL:
>
> (async/<!! (async/into [] channel))
>
> This seems needlessly clunky. Is this really the best way to accomplish
> this?
>
> (2) async/map> is deprecated, what's the alternative, exactly?
>
> (let [ch (async/to-chan [1 2 3])]
> (async/map> inc ch))
>
> AFAICT this would produce a channel, which when consumed would yield the
> values 2 3 4, correct?
>
> Now I suppose if I didn't already have the channel ch, I could create one
> with an associated transformation function, and then stuff the values 1 2 3
> into it somehow, right?
>
> (let [ch (async/chan nil (map inc))]
> (async/onto-chan ch [1 2 3])
> ch)
> ;; returns a channel yielding items 2, 3, 4
>
> But, I'm not clear at all how I can apply the operation (inc) to the all
> values yielded by a channel I already have in my hand.
>
> Any help would be appreciated. I feel like I'm missing some critical bit
> of insight and that async and transducers might just fall into place for me
> if I could only find out what that bit is.
>
> // Ben
>
> --
> 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.
>
--
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.