Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clojure filter map by keys

Tags:

clojure

I'm following this example: http://groups.google.com/group/clojure/browse_thread/thread/99b3d792b1d34b56

(see the last reply)

And this is the cryptic error that I get:

Clojure 1.2.1
user=> (def m {:a "x" :b "y" :c "z" :d "w"})
#'user/m
user=> (filter #(some % [:a :b]) m)
java.lang.IllegalArgumentException: Key must be integer
(user=>

Also I don't understand why this would even work. Isn't (some ...) going to return the first matching value, "x", every time? I'm a total noob at clojure and just trying to learn.

Please enlighten me.

like image 652
Kevin Avatar asked Aug 26 '11 16:08

Kevin


1 Answers

I guess I just needed to read the docs more:

(select-keys m [:a :b])

Although I'm still not sure what the intention was with the example I found...

like image 147
Kevin Avatar answered Oct 08 '22 03:10

Kevin