Other Handy Map Functions

If you need to get hold of all the keys in a map—well, you can guess the function name:

 (keys book)

Evaluate that expression and you will end up with a collection of the keys of your map, something like this:

 (:title :author :published)

Or it might be (:published :title :author) or (:author :published :title); the maps that you create with the literal {} or the hash-map function make no promises about the order of their keys.

Sorted Maps

images/aside-icons/info.png

There is a second flavor of map that keeps its keys sorted. You can make one of these sorted maps with the aptly named function sorted-map.

In much the same way that you can get ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.