types.map

Provides functions for creating and manipulating unordered maps.

get

Description

Returns the value for the given key name from the provided map. If a vector of key names are provided, all of their values are returned in the listed order.

An optional default value may be provided which will be returned for any key which is not present in the map. Otherwise a nil is returned.

Usage

<map> <key name>|<vector of keys> [<default value>]

Examples

:emphasize-lines: 2,5

(get { :first-name "Bobby" :last-name "Sue" } :last-name)
"Sue"

(get { :a 10 :b 20 :c 30 :d 40 } [:a :c :e] 0)
(10 30 0)

keys

Description

Returns a list of keys from the given map, in no guaranteed order.

Usage

<map>

Examples

:emphasize-lines: 2

(keys { :first-name "Bobby" :last-name "Sue" })
(:first-name :last-name)

values

Description

Returns a list of values from the given map, in no guaranteed order.

Usage

<map>

Examples

:emphasize-lines: 2

(keys { :first-name "Bobby" :last-name "Sue" })
("Bobby" "Sue")

assoc

Description

Returns a new map containing the existing keys and values, as well as any new key-value pairs provided. Values default to undefined, and keys that already exist will have their values replaced.

Multiple key-value pairs may be provided. Providing no new key-value pairs will simply return the existing map.

Usage

<map> [<key> [<value>] [<key> [<value>] ...]]

Examples

:emphasize-lines: 2

(assoc { :old-key "foo" } :new-key "bar")
{ :old-key "foo" :new-key "bar" }