Accessing Collections

The purpose of our collections is to store our data, but they’re only useful if we can get the data back out of the collection. Let’s first consider the collections that support indexed lookup by a key.

Indexed Access

Maps and vectors are the two indexed collections provided in Clojure. Vectors use 0-based indexes and are treated as associative collections from index to element. The records that we saw while modeling our domain also implement the map interfaces and can be treated as indexed collections.

Indexed collections support lookup by three methods. The first is by invoking the get function with the collection and a key. The second is by invoking the collection itself with a key. The third is by invoking a keyword ...

Get Clojure Applied now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.