A map is an associative collection that stores values under keys. Map operations distinguish key presence from value truthiness, making explicit membership checks important when a key maps to nil. section 8.2.3
Use these operations to inspect map structure and membership:
- contains? checks whether a key exists in hash maps, sorted maps, array maps, and Java map types; it returns false when a key is absent, even if a value would be truthy elsewhere. section 8.2.3
- keys returns a sequence of keys, while vals returns a sequence of values. Ordering depends on the map type but remains consistent for the same input. section 11.2.1
- Both functions also accept Java maps and collections of java.util.Map$Entry objects; invalid map-like inputs can raise ClassCastException. section 11.2.1
Test presence when nil is a valid value
(def m {:a 1 :b nil :c 3}) (if (get m :b) "Key found" "Key not found") ;; "Key not found" (if (contains? m :b) "Key found" "Key not found") ;; "Key found"









































