Created
April 16, 2020 08:40
-
-
Save cddr/82f1656e3bd1409af632d36ad1b804e2 to your computer and use it in GitHub Desktop.
Enumerate parameters permitted by some clojure spec
This file contains hidden or 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 scratch.ns | |
(:require | |
[clojure.spec.alpha :as s])) | |
(s/def ::foo string?) | |
(s/def ::bar string?) | |
(s/def ::baz string?) | |
(s/def ::yolo (s/keys :req-un [::foo ::bar] | |
:opt-un [::baz])) | |
(let [[_ & rest] (s/form ::yolo)] | |
(let [entity-def (->> (partition 2 rest) | |
(map vec) | |
(into {}))] | |
(concat | |
(:req-un entity-def) | |
(:opt-un entity-def)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment