Skip to content

Instantly share code, notes, and snippets.

@eyston

eyston/spec.clj Secret

Last active March 27, 2017 00:07
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 eyston/c797efc5e4c07304e0c331b97decd107 to your computer and use it in GitHub Desktop.
Save eyston/c797efc5e4c07304e0c331b97decd107 to your computer and use it in GitHub Desktop.
(s/def ::field-name (s/conformer (fn [x]
(cond
(keyword? x)
{:name x :arguments nil}
(and (list? x)
(keyword? (first x))
(map? (second x)))
(let [[name args] x]
{:name name :arguments args})
:else ::s/invalid))))
(s/def ::field-name (s/and (s/or :simple keyword?
:args (s/cat :name keyword? :args map?))
(s/conformer
(fn [[type conform]]
(case type
:simple {:name conform}
:args conform))
(fn [{:keys [name args] :as conform}]
(if (seq args)
[:args conform]
[:simple name])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment