• (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.

1 Example top

  • user=> (nth ["a" "b" "c" "d"] 0)             
    "a"
    user=> (nth ["a" "b" "c" "d"] 1)             
    "b"
    user=> (nth [] 0 "nothing found")
    "nothing found"
    user=> (nth [0 1 2] 77 1337)
    1337
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:824 top

(defn nth
  "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."
  {:inline (fn  [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf)))
   :inline-arities #{2 3}
   :added "1.0"}
  ([coll index] (. clojure.lang.RT (nth coll index)))
  ([coll index not-found] (. clojure.lang.RT (nth coll index not-found))))
Vars in clojure.core/nth:
Used in 0 other vars

Comments top

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