It seems you want to use the nth function.
From the docs for this feature:
clojure.core/nth ([coll index] [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.
This last sentence means that, in practice, nth is slower for “farther” elements in the sequence, without guaranteeing faster work for collections that, in principle, support faster access (~ O (n)) to indexed elements. For sequences (clojure) this makes sense; The clojure seq API is based on the linked list API and in the linked list, you can only access the nth element by going through each element in front of it. Keeping this constraint is what makes specific list implementations interchangeable with lazy sequences.
Clojure collection access functions are usually designed this way; functions that have significantly better access times to specific collections have separate names and cannot be used “accidentally” in slower collections.
As an example of a collection type that supports fast random access to items, clojure vectors can be called; (index-index of a vector collection) gives an element in the index index number - and note that clojure seqs are not callable.
source share