This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-06
Channels
- # announcements (16)
- # aws (9)
- # babashka (76)
- # beginners (92)
- # boot (1)
- # cider (18)
- # clara (7)
- # clj-kondo (26)
- # clojure (104)
- # clojure-europe (4)
- # clojure-nl (11)
- # clojure-spec (11)
- # clojure-survey (101)
- # clojure-uk (35)
- # clojuredesign-podcast (18)
- # clojurescript (8)
- # core-async (29)
- # data-science (1)
- # datomic (13)
- # emacs (4)
- # fulcro (20)
- # graalvm (14)
- # instaparse (2)
- # jobs (1)
- # juxt (6)
- # malli (5)
- # off-topic (30)
- # onyx (3)
- # planck (1)
- # project-updates (7)
- # re-frame (38)
- # reagent (30)
- # reitit (14)
- # remote-jobs (2)
- # shadow-cljs (50)
- # sql (8)
Say I have a go block, and I need to mapcat a collection inside that go block, but for every element inside the collection I also use a go block? So what I did is:
(go (into [] (mapcat (fn [e] (go (something e)))) [1 2 3])
But now I don't want my outer go block to return a vector of channels, so I'd like to take the value out of them, but I would need another map or for or anything which would have a nested fn with a go block doing a take again in it, and then I'd have the same issue
Hum, my solution for now is to do this:
(go
(loop [acc [] coll (into []
(map
(fn [c]
(go
(<! (somefn c))))
[1 2 3)]
(if-let [ch (first coll)]
(recur (conj acc (<! ch)) (next coll))
(into [] cat acc)))))
Because the second arg of async/into is supposed to be a channel, not an ISeq of channels
it would work with async/merge in place of map though
err, merge wrapping map, sorry
is [10] really a valid buff-or-n ?
So it does seem you can, async/merge and then async/into and then async/<!. At that point, I might prefer my loop
variant 😛
I don't know what you are doing now, but if you wrap in apply concat, my async/nto line completely replaces your earlier loop+into
(apply concat
(async/into []
(map (constantly (async/go [1 2])) [1 2 3])))
Throws java.lang.IllegalArgumentException: No implementation of method: :take! of protocol: #'clojure.core.async.impl.protocols/ReadPort found for class: clojure.lang.LazySeqFundamentally I'm trying to do:
(async/<!!
(async/go
(mapcat (constantly (async/go [1 2])) [1 2 3])))