Skip to content

Instantly share code, notes, and snippets.

@yayitswei
Last active January 27, 2017 04:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yayitswei/fc60da9271452716ae2a197c945a4b3e to your computer and use it in GitHub Desktop.
verbose use of s/conform
(s/def ::button-template (s/cat :text string? :link (s/spec ::mb/link)))
(s/def ::button-attachment (s/keys :req [::action/text ::mb/link]))
(s/def ::button-ish (s/or ::button-template ::button-template
::button-attachment ::button-attachment))
(defmulti ->button-attachment (fn [b]
{:pre [(s/valid? ::button-ish b)]}
(first (s/conform ::button-ish b))))
(defmethod ->button-attachment ::button-attachment [b] b)
(defmethod ->button-attachment ::button-template [[text link]]
{::action/text text ::mb/link link})
(->button-attachment {::action/text "hi" ::mb/link [:link]})
(->button-attachment ["hi" [:link]])
(->button-attachment "hi")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment