This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-06-30
Channels
- # admin-announcements (19)
- # announcements (4)
- # beginners (22)
- # boot (76)
- # cider (92)
- # clojure (235)
- # clojure-berlin (3)
- # clojure-germany (1)
- # clojure-italy (8)
- # clojure-japan (18)
- # clojure-russia (26)
- # clojure-sg (1)
- # clojure-uk (25)
- # clojurescript (55)
- # code-reviews (7)
- # core-async (53)
- # datomic (13)
- # euroclojure (63)
- # jobs (39)
- # ldnclj (45)
- # off-topic (9)
- # om (7)
- # onyx (6)
- # reading-clojure (1)
- # reagent (5)
- # yada (22)
The code from this page: https://github.com/clojure/core.async/wiki/Go-Block-Best-Practices
(defn load-urls
"Spools the results of loading several urls onto a channel.
does this without creating temporary channels or go blocks"
[urls out-c]
(http-call
(first urls)
(fn [response]
(put! out-c response (fn [_] (load-urls (next urls) out-c))))))
(load-urls urls)
Been pulling my hair out trying to eliminate this error in a go-loop: clojure.lang.ExceptionInfo: Can't recur here at line 182
So my code was fine after all, just needed to require go-loop
- would have helped if the error message was better
does anyone have a good example of using a transducer to extract info from a cljs event object?
@meow: like this one? https://github.com/cognitect/async-webinar/blob/master/src/webinar/core.cljs#L153
@samflores: sort of
This is what I've got so far for feeding the channel:
(defn extract-mouse-info [e]
{:x (.-clientX e) :y (.-clientY e)})
(defn get-mouse-channel
([]
(get-mouse-channel (sliding-buffer 1)))
([buffer]
(chan buffer (map (completing extract-mouse-info)))))
(defn listen-for! [target event-type channel]
(events/listen target event-type #(put! channel %))
channel)
(defn listen-for-mouse-move! [channel]
(listen-for! js/window EventType.MOUSEMOVE channel))
(defn channel-for-mouse-move!
([]
(listen-for-mouse-move! (get-mouse-channel)))
([buffer]
(listen-for-mouse-move! (get-mouse-channel buffer))))
completing
is a helper to give reducing functions (fn [acc input])
an extra needed arity for use with transduce
I believe completing
is intended to be used when creating functions that produce transducers
if you have a call to reduce that uses transients, you'd do this (reduce conj! (transient []) collection)
but that leaves you with a transient vector at the end, you need a way of completing the reduction
which gives you back
(fn ([coll] (persistent! coll))
([coll input] (conj! coll input)))
Adding it all together with transduce, as reduce doesn't know about that extra arity:
(transduce (map whatever) (completing conj! persistent!) (transient []) coll)
completing is all about the reducing function itself, not the transducer that manipulates the reducing fn
@samflores: no, I haven't
here is the link if you want to: http://cognitect.com/events/webinars
@samflores: cool, thanks. I'm really digging core.async
I went the same way some time ago, but eventually ended up using https://clojars.org/ca.brentvatne/flux
sweet, I just experimented with channels in reagent, but that didn’t work out too well. But I like the idea very much.
@samflores: I'll check that out, thanks.