This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-24
Channels
- # announcements (5)
- # beginners (184)
- # calva (32)
- # cider (29)
- # clj-kondo (1)
- # cljdoc (29)
- # cljsrn (6)
- # clojure (44)
- # clojure-dev (36)
- # clojure-europe (9)
- # clojure-italy (18)
- # clojure-losangeles (1)
- # clojure-nl (3)
- # clojure-spec (7)
- # clojure-uk (30)
- # clojure-ukraine (1)
- # clojuredesign-podcast (8)
- # clojurescript (65)
- # code-reviews (21)
- # core-async (25)
- # cursive (51)
- # data-science (3)
- # datascript (2)
- # datomic (25)
- # emacs (14)
- # events (1)
- # figwheel-main (3)
- # fulcro (3)
- # graalvm (5)
- # jackdaw (17)
- # kaocha (14)
- # luminus (5)
- # off-topic (17)
- # pathom (7)
- # pedestal (2)
- # re-frame (71)
- # reagent (25)
- # shadow-cljs (83)
- # spacemacs (31)
- # sql (92)
- # tools-deps (23)
- # vim (102)
- # xtdb (5)
guys, what's the preferred method of running a side-effecting function over a (potentially lazy) collection of items?
I guess mapv is good if you need the return value
doall or dorun depending on whether you want the return value
doseq if you want a binding
has for like semantics
I love it when I am shown a new (to me) clojure built-in
What bronsa said. run!
is specifically meant for this… doseq
, dorun
, mapv
and others have slightly different purposes. run!
is specifically meant for where you have a side effecting function that you want to apply to each thing in the collection.
to be fair doseq
/`dorun` are also specifically meant for side-effecting over collections
you could argue that doall
isn't specifically about that, but the docstring also explicitely mentions side-effecty stuff
>to be fair doseq
/`dorun` are also specifically meant for side-effecting over collections
Absolutely. My point is really that run!
is really meant for when you have a side effecting procedure of the right shape already; which is (nearly) what @lady3janepl asked for i.e. (run! println coll)
is arguably better than (doseq [v coll] (println v))
. Though if you’re not breaking the side effect out into a procedure you can use doseq
… there’s lots of subtlety around picking the right one here — most of which is arguably also splitting hairs.
Though you might prefer doseq
if you needed to apply other args too.
run!
came after doseq
and dorun
I guess doseq
breaks composability because it is a macro which may have been one of the usecases for adding run!
We ended up using run!
all over the place. Much tidier than doseq
/`dorun` most of the time, as long as you don't care about anything apart from the side effect.
yeah run!
was added in 1.7
doseq
etc were pre 1.0