liveBook · Manning

Array-map

As explained in Clojure: The Essential Reference

array-map is a Clojure constructor that creates an array-backed associative map.

array-map creates a PersistentArrayMap: an associative map with hash-map-like behavior, linear implementation, and insertion order during iteration. section 11.1.2

Its contract is:

  • Accepts an even sequence of key-value arguments, including no arguments. section 11.1.2
  • Throws IllegalArgumentException when a value is missing. section 11.1.2
  • Lets the last value override duplicate keys while retaining metadata from the original key. section 11.1.2
  • May promote itself to a PersistentHashMap when assoc or related operations require scaling; it does not scale beyond a few hundred entries. section 11.1.2

Preserving column order

Use an array-map to define CSV columns in export order, pairing each column name with its database field and validation function. Iteration then follows the declared column sequence.

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, exceptions, duplicate-key behavior, ordering, implementation, and automatic promotion limits.
Examples
Uses map literals, type inspection, assoc promotion, ordered customer formats, metadata, and CSV-oriented column definitions.
What you can do after
Apply array-map to construct ordered associative data and recognize when updates change its concrete map type.
How it connects
Relates to hash-map, sorted-map, assoc, zipmap, metadata, and CSV export.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.