You're viewing version 1.2.0 of peek. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (peek coll)
For a list or queue, same as first, for a vector, same as, but much
more efficient than, last. If the collection is empty, returns nil.

2 Examples top

  • user=> (def large-vec (vec (range 0 10000)))
    #'user/large-vec
    
    user=> (time (last large-vec))
    "Elapsed time: 1.279841 msecs"
    9999
    
    user=> (time (peek large-vec))
    "Elapsed time: 0.049238 msecs"
    9999
    
  • user=> (peek '(:a :b :c))
    :a
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/first

    Returns the first item in the collection. Calls seq on its argume

  • 0
    clojure.core/pop

    For a list or queue, returns a new list/queue without the first ite

  • 0
    clojure.core/conj

    conj[oin]. Returns a new collection with the xs 'added'. (conj ni

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1129 top

(defn peek
  "For a list or queue, same as first, for a vector, same as, but much
  more efficient than, last. If the collection is empty, returns nil."
  {:added "1.0"}
  [coll] (. clojure.lang.RT (peek coll)))
Vars in clojure.core/peek: defn
Used in 1 other vars content-handler

Comments top

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