Last active
December 16, 2015 03:58
-
-
Save timmc/5373281 to your computer and use it in GitHub Desktop.
Templating of deftypes
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
(deftype MultiErrorReporter | |
[reporters] | |
ErrorReporter | |
(constraint-error [_ state constraint] | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (constraint-error state constraint))]))) | |
(extraneous-path-error [_ state extra-path] | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (extraneous-path-error state extra-path))]))) | |
(missing-path-error [_ state missing-path] | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (missing-path-error state missing-path))]))) | |
(predicate-fail-error [_ state val-at-path pred] | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (predicate-fail-error state val-at-path pred))]))) | |
(instance-of-fail-error [_ state val-at-path expected-class] | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (instance-of-fail-error state val-at-path expected-class))]))) | |
(pre-validation-transform-error [_ state val-at-path pre-validation-transform-fn] | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (pre-validation-transform-error | |
state val-at-path pre-validation-transform-fn))])))) |
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
(inject-forms | |
(deftype MultiErrorReporter | |
[reporters] | |
ErrorReporter | |
^:splice methods) | |
[methods `(do-template | |
[method argvec] (method argvec | |
(into {} (for [[k ^ErrorReporter rep] reporters] | |
[k (. rep (name ~@argvec))]))) ;; yes, I'm aware ~@ doesn't work here -- it's to show my intent | |
(constraint-error [_ state constraint]) | |
(extraneous-path-error [_ state extra-path]) | |
(missing-path-error [_ state missing-path]) | |
(predicate-fail-error [_ state val-at-path pred]) | |
(instance-of-fail-error [_ state val-at-path expected-class]) | |
(pre-validation-transform-error | |
[_ state val-at-path pre-validation-transform-fn]))]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment