;; `project` strips out unwanted key/value pairs from a set of maps.
;; Suppose you have these descriptions of cows:
user=> (def cows #{ {:name "betsy" :id 33} {:name "panda" :id 34} })
#'user/cows
;; You care only about the names. So you can get them like this:
user=> (project cows [:name])
#{{:name "panda"} {:name "betsy"}}
;; `project` strips out unwanted key/value pairs from a set of maps.
;; Suppose you have these descriptions of cows:
user=> (def cows #{ {:name "betsy" :id 33} {:name "panda" :id 34} })
#'user/cows
;; You care only about the names. So you can get them like this:
user=> (project cows [:name])
#{{:name "panda"} {:name "betsy"}}
Comments top
3 comment(s) for project.
is there a function that is like project, but returns a set of hash-maps with with all the keys but the ones project was given?
This doesn't exist in clojure.set, but I think it would be what you wanted.
(defn project-not [xrel ks] ;; convert the given key sequence into a hash-set ;; This represents keys that you don't want included (let [ks-set (into #{} ks)] ;; Do a projection on the keys that are not in ks (clojure.set/project xrel ;; Assumes xrel is a set of maps ;; Grab the first map and extract the keys ;; Then remove any keys that are in ks-set ;; This will leave the remaining keys for ;; projection (remove #(ks-set %) (keys (first xrel)))))) user> (project-not cows [:id]) #{{:name "panda" {:name "betsy"}}(defn project-not [xrel ks] ;; convert the given key sequence into a hash-set ;; This represents keys that you don't want included (let [ks-set (into #{} ks)] ;; Do a projection on the keys that are not in ks (clojure.set/project xrel ;; Assumes xrel is a set of maps ;; Grab the first map and extract the keys ;; Then remove any keys that are in ks-set ;; This will leave the remaining keys for ;; projection (remove #(ks-set %) (keys (first xrel)))))) user> (project-not cows [:id]) #{{:name "panda" {:name "betsy"}}it strikes me as being very odd that the key set is a vector as opposed to vargs