This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-15
Channels
- # admin-announcements (3)
- # aws (1)
- # beginners (1)
- # boot (73)
- # cider (1)
- # clojure (146)
- # clojure-japan (4)
- # clojure-nl (3)
- # clojure-russia (90)
- # clojurescript (72)
- # community-development (17)
- # core-async (10)
- # cursive (60)
- # datomic (15)
- # devcards (7)
- # emacs (5)
- # events (5)
- # hoplon (3)
- # instaparse (3)
- # ldnclj (48)
- # leiningen (5)
- # off-topic (27)
- # om (120)
- # onyx (31)
- # re-frame (7)
- # reagent (7)
- # ring-swagger (17)
- # yada (3)
Hi, does anybody know why async/to-chan doesn’t create a channel with 1 element buffer, but with min(100,collLength). Performance reasons?
(defn to-chan
"Creates and returns a channel which contains the contents of coll,
closing when exhausted."
[coll]
(let [ch (chan (bounded-count 100 coll))]
(onto-chan ch coll)
ch))
I’m using this function very often, but just recently found out that it breaks all the laziness of my collections like:
(defn process [n] (print n) n)
(def c (async/to-chan (map process (range 10)))) ;; Prints 0 - 9
@artemyarulin: to-chan
is a convenience method for onto-chan
, you can supply your own buffer to onto-chan
that behaves as you wish
to-chan
is implemented with onto-chan
Yeah, thx - I know it. I just wonder why the buffer is not 1 length by default
Probably just a performance thing so that it spools ahead of lazy evaluation
Ah ok, thx. I’ll use async/onto-chan then
@artemyarulin: generally putting side effects in lazy sequences is an anti pattern, but it looks like what you put up was just a demo?
Yeah, I know it. It was just for the purpose of showing that laziness got lost
Thought so
thx for telling in any case