store/[org.clojure/clojure "1.6.0"] clj::clojure.core/doall

Community Documentation

Edit

Arities

[coll] -> coll
[n coll] -> coll

Docstring

Walks the first n of a sequence, or its full length if n is not provided forcing elements of the sequence to be computed. Returns the head of the sequence as if no elements had been consumed, however the first n will have been forced and will reside in memory.

Notes

A wrapper around clj::clojure.core/dorun which returns the head of the forced 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. See clj::clojure.core/map for some discussion of this behavior. doall can be used to force any effects to occur by causing sequence elements to be computed.

See Also

Source

(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))

Example 1

Edit
;; Nothing is printed because map returns a lazy-seq
(def foo (map println [1 2 3]))
;; => #'user/foo

;; Get the value of foo
foo
;; > 1
;; > 2
;; > 3
;; => (nil nil nil)

;; doall forces the seq to be realized
(def foo (doall (map println [1 2 3])))
;; > 1
;; > 2
;; > 3
;; => #'user/foo

;; Like above, but note the difference
foo
;; => (nil nil nil)

;; Where
(doall (map println [1 2 3]))
;; > 1
;; > 2
;; > 3
;; => (nil nil nil)

Uses on crossclj