Skip to content

Instantly share code, notes, and snippets.

@abp
Last active January 4, 2018 13:04
Show Gist options
  • Save abp/0c4106eba7b72802347b to your computer and use it in GitHub Desktop.
Save abp/0c4106eba7b72802347b to your computer and use it in GitHub Desktop.
(require '[schema.core :as s])
(require '[schema.coerce :as coerce])
(require '[schema.utils :as utils])
(defn filter-schema-keys
[m schema-keys extra-keys-walker]
(reduce-kv (fn [m k v]
(if (or (contains? schema-keys k)
(and extra-keys-walker
(not (utils/error? (extra-keys-walker k)))))
m
(dissoc m k)))
m
m))
(defn map-filter-matcher
[s]
(when (or (instance? clojure.lang.PersistentArrayMap s)
(instance? clojure.lang.PersistentHashMap s))
(let [extra-keys-schema (#'s/find-extra-keys-schema s)
extra-keys-walker (when extra-keys-schema (s/walker extra-keys-schema))
explicit-keys (some->> (dissoc s extra-keys-schema)
keys
(mapv s/explicit-schema-key)
(into #{}))]
(when (or extra-keys-walker (seq explicit-keys))
(fn [x]
(if (map? x)
(filter-schema-keys x explicit-keys extra-keys-walker)
x))))))
@hikalkan
Copy link

hikalkan commented Jan 4, 2018

Hi @abp, can you contact me from [email protected]. I'm interesting in to take your Github account name (abp) for our open source asp.net boilerplate project (https://github.com/aspnetboilerplate/aspnetboilerplate) if we can make a deal.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment