Skip to content

Instantly share code, notes, and snippets.

View mbuczko's full-sized avatar

Michał Buczko mbuczko

View GitHub Profile
(defmacro assert-all
[& pairs]
`(do (when-not ~(first pairs)
(throw (IllegalArgumentException.
(str (first ~'&form) " requires " ~(second pairs) " in " ~'*ns* ":" (:line (meta ~'&form))))))
~(let [more (nnext pairs)]
(when more
(list* `assert-all more)))))
(defmacro when-let*
@mbuczko
mbuczko / validation.clj
Last active June 28, 2019 20:30 — forked from ewilazarus/validation.clj
clojure / validation
(ns sagaz-back.validation)
; Helper functions
(defn validate* [field value regexp]
(if-not (re-matches regexp value)
(keyword (str "invalid-" (name field)))))
(defn validate [data criteria]
(-> (reduce-kv (fn [acc k re] (conj acc (validate* k (k data) re)))