Skip to content

clojure.core/array-map

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 5 Runnable: 3
([] [& keyvals])

Constructs an array-map. If any keys are equal, they are handled as if by repeated uses of assoc.

Examples

by Jacolyte on
by kumarshantanu on
by steveminer on . May have evaluation errors.
by TradeIdeasPhilip on
by tomdl89 on . May have evaluation errors.

Note by Jacolyte

The definition is kind of short, IMO. More descriptively, array-map creates a mapping with arrays being the keys and the values. It doesn't seem like array-map cares whether or not the keys/values are arrays, although it doesn't seem to like sequences.

Note by steveminer

An array-map maintains the insertion order of the keys. Look up is linear, which is not a problem for small maps (say less than 10 keys). If your map is large, you should use hash-map instead.

When you assoc onto an existing array-map, the result is a new array-map with the new key as the first key. The rest of the keys are in the same order as the original. Functions such as seq and keys will respect the key order.

Note that assoc will decide to return a hash-map if the result is too big to be efficient.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.