-
-
Save devn/039ac6dbdb6587fa263d to your computer and use it in GitHub Desktop.
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
(defn filter-vals | |
[pred m] | |
(let [reduce-fn (fn [assoc-fn] (fn [m k v] (if (pred v) (assoc-fn m k v) m)))] | |
(if (instance? clojure.lang.IEditableCollection m) | |
(with-meta | |
(persistent! (reduce-kv (reduce-fn assoc!) (transient (empty m)) m)) | |
(meta m)) | |
(reduce-kv (reduce-fn assoc) (empty m) m)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment