Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Forked from michaelsbradleyjr/qc-3.clj
Last active August 29, 2015 14:20
Show Gist options
  • Save kindlychung/b4b87b9951c05a9cd762 to your computer and use it in GitHub Desktop.
Save kindlychung/b4b87b9951c05a9cd762 to your computer and use it in GitHub Desktop.
(defn qc [op & pairs]
(assert (even? (count pairs)))
(fn [coll]
(doseq [[pred msg] (partition 2 pairs)]
(when-not (pred coll)
(throw (IllegalArgumentException. msg))))
(apply op coll)))
(def f1 (qc +
#(= 2 (count %)) "coll must have length 2."
#(even? (first %)) "first elem must be even."
#(odd? (second %)) "second elem must be odd."))
(def f2 (qc -))
(def f3 (qc /))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment