Skip to content

Instantly share code, notes, and snippets.

@devn
Created November 11, 2014 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devn/039ac6dbdb6587fa263d to your computer and use it in GitHub Desktop.
Save devn/039ac6dbdb6587fa263d to your computer and use it in GitHub Desktop.
(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