-
-
Save yayitswei/fc60da9271452716ae2a197c945a4b3e to your computer and use it in GitHub Desktop.
verbose use of s/conform
This file contains 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
(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