Skip to content

Instantly share code, notes, and snippets.

@cddr
Created April 16, 2020 08:40
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 cddr/82f1656e3bd1409af632d36ad1b804e2 to your computer and use it in GitHub Desktop.
Save cddr/82f1656e3bd1409af632d36ad1b804e2 to your computer and use it in GitHub Desktop.
Enumerate parameters permitted by some clojure spec
(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