3

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

1 Answer 1

6

Yes, map? is the inbuilt function

(map? {:a 1})
=> true
(map? [1])
=> false
RobinGower
9586 silver badges14 bronze badges
answered May 21, 2015 at 9:41
Sign up to request clarification or add additional context in comments.

3 Comments

conj.io looks like a great resource. would indeed be helpful! :)
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.
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 one

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.