Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Forked from michaelsbradleyjr/qc-2.clj
Last active August 29, 2015 14:20
Show Gist options
  • Save kindlychung/62122bdf8a6049655cc7 to your computer and use it in GitHub Desktop.
Save kindlychung/62122bdf8a6049655cc7 to your computer and use it in GitHub Desktop.
(defn qc [op & pairs]
(assert (even? (count pairs)))
(fn [coll]
(doall
(map (fn [[pred msg]]
(when-not (pred coll)
(throw (IllegalArgumentException. msg))))
(partition 2 pairs))
(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