Last active
February 29, 2016 17:09
-
-
Save michalmarczyk/48a9ffe2b99fc1f2dbf7 to your computer and use it in GitHub Desktop.
validateur nesting
This file contains hidden or 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
(defn validate-under [attr validator] | |
(fn [m] | |
(let [result (validator (get m attr))] | |
[(empty? result) (v/nest attr result)]))) | |
(comment | |
(def example-v | |
(v/validation-set | |
(validate-under :foo (v/validation-set (v/presence-of :bar))))) | |
(example-v {:foo {:bar 1}}) | |
;= {} | |
(example-v {:foo {}}) | |
;= {[:foo :bar] #{"can't be blank"}} | |
(example-v {}) | |
;= {[:foo :bar] #{"can't be blank"}} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment