Last active
July 9, 2018 19:09
-
-
Save uwo/ea75d4fc11014df8776a3c23020c5b16 to your computer and use it in GitHub Desktop.
key selection
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
{:paths ["."]} |
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
(ns key-selection | |
(:require [clojure.spec.alpha :as s])) | |
(defn select-keys-by-ns | |
[ns-re m] | |
(into {} (filter #(re-find ns-re (namespace (key %))) m))) | |
(defn select-keys-by-ns-exact | |
"A quick idiom for resolving autogenerated namespaces is | |
(namepsace ::_) or | |
(namespace ::namespace-alias/_)" | |
[ns m] | |
(into {} (filter #(= (namespace (key %)) ns) m))) | |
(s/fdef select-keys-by-ns-exact | |
:args (s/cat :namespace string? | |
:map (s/map-of keyword? any?)) | |
:ret (s/map-of keyword? any?)) | |
#_(select-keys-by-ns-exact (namespace ::_) {::test 1 ::two 21 :blah/asdf 3}) | |
#_(select-keys-by-ns #"asdf" {:asdf/test "asdf" :qwer/test "qwer"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment