I'm trying get a clojure function to detect if the value passed is a map. For example,
user=> (if-map {:foo 1}) ;Should return true
true
user=> (if-map "hello") ;Returns false
false
Is there a pre-built function serving this already?
asked May 21, 2015 at 9:36
Coding active
1,6903 gold badges25 silver badges40 bronze badges
1 Answer 1
Yes, map? is the inbuilt function
(map? {:a 1})
=> true
(map? [1])
=> false
answered May 21, 2015 at 9:41
Mark Fisher
9,9063 gold badges34 silver badges41 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Coding active
conj.io looks like a great resource. would indeed be helpful! :)
Thumbnail
Up to a point, Lord Copper:
(map? x) returns whether x implements IPersistentMap. It could be something other than a clojure.lang.PersistentHashMap or other built-in map implementation. But it is what you ought to want to know: Clojure is built around interfaces, not specific implementations.Mark Fisher
umm. yeah. i guess. she asked for checking a standard clojure map. in clojure. as per tag
clojure, and as per the question "Clojure - map values", so i'm not getting your point here. does your comment add anything here? if there's an issue with my answer, please provide a better onelang-clj