nedap/speced.def

defprotocol: metadata 'syntax' tedious for common types

vemv opened this issue · 0 comments

vemv commented

I'm finding this pattern tedious:

(spec/def ::string string?)

(speced/defprotocol Config
  "Getters for this app's most used paths."
  (^::string seo-name [this] "The app name for SEO purposes."))

...The problem being that I have to define the ::string spec once per ns.

Possible solutions:

  • Bundle some these common specs with the library
    • ::string, ::int, ::vector, etc
    • Sample usage: (^::speced/string seo-name [this] "The app name for SEO purposes.")
    • Handy but, but bundling dozens of specs isn't elegant
  • Infer specs from Clojure's built-in type annotation facility
    • Sample usage: (^Int seo-name [this] "The app name for SEO purposes.")
    • For ^Int, we create a spec on-the-fly: (partial instance? the-type)
    • Of course, we opportunistically make sure to emit efficient code!
  • Accept a generic key, e.g. ::speced/spec (or ::spec)
    • Sample usage: (^{::speced/spec string?} seo-name [this] "The app name for SEO purposes.")

The 3 options aren't mutually exclusive.