Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am chrisdevo on github.
  • I am cdevine (https://keybase.io/cdevine) on keybase.
  • I have a public key ASCvYbpoCYfH8XuuFnatt5-l9FYF0isQoP1qAfZrISrWiAo

To claim this, I am signing this object:

@ChrisDevo
ChrisDevo / pre_assertion_gist.clj
Created March 17, 2016 17:16
Using `is` in :pre assertion
;; Using `assert` in :pre doesn't work because `(assert true)` returns `nil`.
;; :pre expects a truthy value, not `nil`.
;; Even though `clojure.test/is` is technically 'test' code (which usually doesn't appear in production code),
;; in this case it provides the behavior I want (custom error messages when validating funtion arguments)
;; with little overhead.
;; Using `assert`
(defn my-fn [bool]
{:pre [(assert bool (format "Custom message returning modified value of bool: %s" (not bool)))]}
(println bool))