Skip to content

clojure.core/peek

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 4 Runnable: 3
([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.

Examples

by pkolloch on . May have evaluation errors.
by TravisHeeter on
by ertugrulcetin on
by ibercode on

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


Content from the matching ClojureDocs page, with authors credited on each contribution.