You're viewing version 1.2.0 of dorun. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

dorun

clojure.core

  • (dorun coll)
  • (dorun n coll)
When lazy sequences are produced via functions that have side
effects, any effects other than those needed to produce the first
element in the seq do not occur until the seq is consumed. dorun can
be used to force any effects. Walks through the successive nexts of
the seq, does not retain the head and returns nil.

3 Examples top

  • user=> (dorun 5 (repeatedly #(println "hi")))
    hi
    hi
    hi
    hi
    hi
    hi
    nil
    
  • user=> (let [x (atom 0)]
             (dorun (take 10 (repeatedly #(swap! x inc))))
             @x)
    10
  • user=> (dorun (map #(println "hi" %) ["mum" "dad" "sister"]))
    hi mum
    hi dad
    hi sister
    nil
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/doall

    When lazy sequences are produced via functions that have side effec

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2442 top

(defn dorun
  "When lazy sequences are produced via functions that have side
  effects, any effects other than those needed to produce the first
  element in the seq do not occur until the seq is consumed. dorun can
  be used to force any effects. Walks through the successive nexts of
  the seq, does not retain the head and returns nil."
  {:added "1.0"}
  ([coll]
   (when (seq coll)
     (recur (next coll))))
  ([n coll]
   (when (and (seq coll) (pos? n))
     (recur (dec n) (next coll)))))
Vars in clojure.core/dorun: and dec defn next pos? seq when

Comments top

No comments for dorun. Log in to add a comment.