This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-06
Channels
- # announcements (1)
- # aws (36)
- # babashka (105)
- # beginners (53)
- # calva (27)
- # cider (5)
- # clj-kondo (10)
- # clojure (232)
- # clojure-europe (4)
- # clojure-italy (6)
- # clojure-losangeles (9)
- # clojure-nl (3)
- # clojure-sanfrancisco (3)
- # clojure-uk (124)
- # clojured (3)
- # clojurescript (57)
- # clojutre (1)
- # core-async (9)
- # core-logic (1)
- # cryogen (23)
- # cursive (35)
- # datomic (12)
- # duct (4)
- # events (1)
- # figwheel-main (3)
- # fulcro (9)
- # graalvm (31)
- # jobs (1)
- # jobs-discuss (85)
- # kaocha (11)
- # leiningen (11)
- # luminus (19)
- # malli (47)
- # meander (12)
- # nrepl (8)
- # off-topic (32)
- # pathom (4)
- # pedestal (2)
- # reagent (7)
- # ring-swagger (1)
- # schema (3)
- # sql (5)
- # tools-deps (114)
- # vim (17)
- # xtdb (12)
So I’m calling a library that gives me a core.async channel. I want to (lazily) map a function over this channel before returning it to the calling code. How can I make this happen?
I’d use core.async/map
, but it seems to be eager (e.g. (def ch (a/map inc [(a/to-chan (range 1000000000))]))
seems to hang)
Maybe with a pipeline+transducer: https://stackoverflow.com/questions/31286167/how-to-create-a-channel-from-another-with-transducers
(def ch (a/map (fn [x] (println x) (inc x)) [(a/to-chan (range 1000000000))]))
=> #'user/ch
0
(a/<!! ch)
=> 1
1
Okay so I looked into this a bit closer. I’m also confused as to why map
is hanging, since it’s definitely not eager (I verified this by mapping a function that prints a message). The same goes for pipeline
. Either way, I decided to stick to map
; hopefully it won’t hang in more realistic scenarios 🙂 Thanks @fmjrey
Maybe you're experiencing chunking http://clojure-doc.org/articles/language/laziness.html#lazy-sequences-chunking
@wombawomba above, isn't a/to-chan going to hang? map's laziness doesn't come into play
that's not the issue, never mind