nth

added
1.0

ns
clojure.core

type
function

(nth coll index) (nth coll index not-found)

Returns the value at the index. get returns nil if index out of
bounds, nth throws an exception unless not-found is supplied.  nth
also works for strings, Java arrays, regex Matchers and Lists, and,
in O(n) time, for sequences.

                ; Note that nth uses zero-based indexing, so that
;   (first my-seq) <=> (nth my-seq 0)
(def my-seq ["a" "b" "c" "d"])
(nth my-seq 0)
; => "a"
(nth my-seq 1)
; => "b"
(nth [] 0)
; => IndexOutOfBoundsException ...
(nth [] 0 "nothing found")
; => "nothing found"
(nth [0 1 2] 77 1337)
; => 1337
            
                (nth ["last"] -1 "this is not perl")
; => "this is not perl"