Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Last active February 29, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalmarczyk/48a9ffe2b99fc1f2dbf7 to your computer and use it in GitHub Desktop.
Save michalmarczyk/48a9ffe2b99fc1f2dbf7 to your computer and use it in GitHub Desktop.
validateur nesting
(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