peek

functionsince v0.0-927 clojure.core/peekEdit
(peek coll)

Details:

Returns the first element of a list; same as first.

Returns the last element of a vector, and much more efficient than using last.

Returns nil if coll is empty.


Examples:

With vectors:

(peek [1 2 3])
;;=> 3

(peek [1 2])
;;=> 2

(peek [1])
;;=> 1

(peek [])
;;=> nil

With lists:

(peek '(1 2 3))
;;=> 1

(peek '(1 2))
;;=> 1

(peek '(1))
;;=> 1

(peek '())
;;=> nil

See Also:


Source docstring:
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.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn peek
  [coll]
  (when-not (nil? coll)
    (-peek coll)))