This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-13
Channels
- # announcements (1)
- # babashka (21)
- # beginners (39)
- # calva (10)
- # cljsrn (4)
- # clojure (133)
- # clojure-europe (27)
- # clojure-nl (2)
- # clojure-uk (1)
- # clojurescript (10)
- # code-reviews (19)
- # cursive (1)
- # data-science (1)
- # deps-new (2)
- # emacs (8)
- # events (4)
- # exercism (3)
- # fulcro (14)
- # introduce-yourself (2)
- # lsp (7)
- # malli (2)
- # meander (2)
- # missionary (6)
- # pathom (6)
- # pedestal (1)
- # releases (1)
- # remote-jobs (1)
- # sci (18)
- # tools-build (2)
what is the difference between using a reactor and reduce ap
to a function and firing it?
(def atm_ (atom 0))
(def s1 (atom 0))
(def s2 (atom 0))
(def a1 (m/ap (let [v (m/?< (m/watch atm_))] (reset! s1 v))))
(def r1 (m/reactor (m/stream! (m/ap (let [v (m/?< (m/watch atm_))] (reset! s2 v))))))
((m/reduce conj a1) prn prn)
(r1 prn prn)
(swap! atm_ inc)
@s1
;; => 1
@s2
;; => 1
stream!
is normally used when you need to dispatch the values of a single flow to several listeners. The backpressure is then collected from the listeners and propagated upstream. In this example, nobody is listening to the stream, therefore there's no backpressure so the flow is consumed at maximal speed, as per reduce
.