core.async: "Deprecated - this function will be removed. Use transducer instead"

267 views
Skip to first unread message

Ben Smith-Mannschott

unread,
Feb 18, 2015, 4:48:05 PM2/18/15
to clo...@googlegroups.com
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

Erik Price

unread,
Feb 18, 2015, 5:44:32 PM2/18/15
to clo...@googlegroups.com
(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

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Malcolm Sparks

unread,
Feb 18, 2015, 9:06:42 PM2/18/15
to clo...@googlegroups.com
I have recently written a blog article which explains how to use transducers with core.async. 

Ben Smith-Mannschott

unread,
Feb 19, 2015, 2:44:26 AM2/19/15
to clo...@googlegroups.com
Thanks Malcolm, you're blog post was a great help to me.

--

Ben Smith-Mannschott

unread,
Feb 19, 2015, 12:37:24 PM2/19/15
to clo...@googlegroups.com
I'm unclear on one thing: what's the purpose of core.async/pipe? In your blog article, you write:

(-> source (pipe (chan)) payload-decoder payload-json-decoder)

(pipe source destination) just copies elements from source to destination. How is that any different than just using source here directly?:

(-> source payload-decoder payload-json-decoder)

What have I missed?

// Ben

On Thu, Feb 19, 2015 at 3:06 AM, Malcolm Sparks <mal...@juxt.pro> wrote:
--

Malcolm Sparks

unread,
Feb 19, 2015, 12:50:45 PM2/19/15
to clo...@googlegroups.com
You're right - thanks for that! I've updated the blog article to remove it.

You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/z1B-42npgaI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages