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:2714 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"
   :static true}
  ([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:
Used in 0 other vars

Comments top

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