clojure.core/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.
Examples¶
Note by tomby42¶
Small reminder:
Do not work for arbitrary seq but just for persistent types implementing clojure.lang.IPersistentStack (like clojure.lang.Persistent*).
Example:
user> (peek (cons 1 '())) ; Evaluation aborted.
do not work because type is clojure.lang.Cons but
user> (peek (conj '() 1)) 1
works because type is clojure.lang.PersistentList.
See also¶
- clojure.core/first (2)
- clojure.core/pop (2)
- clojure.core/conj (9)
Content from the matching ClojureDocs page, with authors credited on each contribution.