Last active
September 8, 2016 15:17
-
-
Save jeroenvandijk/2748b6af74c6ba6f8fd7dffaed5cc390 to your computer and use it in GitHub Desktop.
multi-spec on vectors
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
(require '[clojure.spec :as s]) | |
;; WARNING: be careful with testing in the repl as reloading doesn't work AFAIK (e.g. changing the dispatch fn). You have to change the multimethod name | |
(do | |
(s/def ::action-type #{:CREATE :DELETE}) | |
(s/def ::entity-id any?) | |
(s/def ::label-action (s/cat :type ::action-type | |
:entity-type #{:label} | |
:entity-id ::entity-id)) | |
(s/def ::template-action (s/cat :type ::action-type | |
:entity-type #{:template} | |
:entity-id ::entity-id)) | |
(defmulti foo-action second) | |
(defmethod foo-action :label [_] | |
::label-action) | |
(defmethod foo-action :template [_] | |
::template-action) | |
;; REVIEW haven't figured out how the retagging works yet, is that related to s/unform? | |
(s/def ::foo-action (s/multi-spec foo-action :entity-type)) | |
(s/conform ::foo-action [:CREATE :template 1 ])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment