Created
April 13, 2013 15:19
-
-
Save ikitommi/5378805 to your computer and use it in GitHub Desktop.
Filtering nested maps in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; here only data used in filtering. | |
(def docs [{:schema {:info {:name "party"}}} | |
{:schema {:info {:name "bonus"}}} | |
{:schema {:info {:name "party"}}}]) | |
;; anonymous function with get-in (72) | |
(filter (fn [doc] (= "party" (get-in doc [:schema :info :name]))) docs) | |
;; anonymous function & threading (66) | |
(filter (fn [doc] (-> doc :schema :info :name (= "party"))) docs) | |
;; anonymous function in shortcut form & get-in (60) | |
(filter #(= "party" (get-in % [:schema :info :name])) docs) | |
;; anonymous function in shortcut form & threading (54) | |
(filter #(-> % :schema :info :name (= "party")) docs) | |
;; macro for creating anonymous function for threading on input | |
(defmacro => [& body] `(fn [c#] (-> c# ~@body))) | |
;; clean & lean (51) | |
(filter (=> :schema :info :name (= "party")) docs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment