1.3.0 permalink Arrow_down_16x16

doall

clojure.core

  • (doall coll)
  • (doall 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. doall can
be used to force any effects. Walks through the successive nexts of
the seq, retains the head and returns it, thus causing the entire
seq to reside in memory at one time.

1 Example top

  • ;; Nothing is printed because map returns a lazy-seq
    user=> (def foo (map println [1 2 3]))
    #'user/foo
    
    ;; doall forces the seq to be realized
    user=> (def foo (doall (map println [1 2 3])))
    1
    2
    3
    #'user/foo
    
    ;; where
    (doall (map println [1 2 3]))
    1
    2
    3
    (nil nil nil)
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2729 top

(defn doall
  "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. doall can
  be used to force any effects. Walks through the successive nexts of
  the seq, retains the head and returns it, thus causing the entire
  seq to reside in memory at one time."
  {:added "1.0"
   :static true}
  ([coll]
   (dorun coll)
   coll)
  ([n coll]
   (dorun n coll)
   coll))
Vars in clojure.core/doall:
Used in 0 other vars

Comments top

2 comment(s) for doall.

Shouldn't we use seq instead of coll in the function signature since we should really pass a sequence?

'seq' is a function; using it in the function args as a value would shadow the function (and thereby making the function seq unusable in that scope)

Log in to add a comment.