Easiest way to search records in Clojure -
i have map in clojure this:
(def stuff #{ {:a "help" :b "goodbye"} {:c "help2" :b "goodbye"} {:a "steve" :b "goodbye"} {:c "hello2" :b "sue"} }) : , want provide search that:
(search stuff "help") : return :
#{ {:a "help" :b "goodbye"} {:c "help2" :b "goodbye"} } : simplest way this?
user=> (defn search [s q] (select #(some (partial re-find (re-pattern q)) (vals %)) s)) #'user/search user=> (search stuff "help") #{{:a "help", :b "goodbye"} {:c "help2", :b "goodbye"}} this trick.
Comments
Post a Comment