1.3.0 permalink Arrow_down_16x16

empty

clojure.core

  • (empty coll)
Returns an empty collection of the same category as coll, or nil

2 Examples top

  • user=> (empty [1 2 3])
    []
    
    user=> (empty (list 1 2 3))
    ()
    
    user=> (map empty [[\a \b] {1 2} (range 4)])
    ([] {} ())
    
    user=> (swap! (atom (range 10)) empty)      
    ()
  • ;; The output will not necessarily be of the same JVM class as the input
    user=> (class (seq [1]))
    clojure.lang.PersistentVector$ChunkedSeq
    
    user=> (class (empty (seq [1])))
    clojure.lang.PersistentList$EmptyList
    
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:4558 top

(defn empty
  "Returns an empty collection of the same category as coll, or nil"
  {:added "1.0"
   :static true}
  [coll]
  (when (instance? clojure.lang.IPersistentCollection coll)
    (.empty ^clojure.lang.IPersistentCollection coll)))
Vars in clojure.core/empty:
Used in 0 other vars

Comments top

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