Created
January 12, 2013 00:03
-
-
Save MichaelDrogalis/4515066 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns dire-example.core | |
(:require [dire.core :refer [with-precondition with-precondition! supervise]])) | |
(defn func1 [x] | |
{:pre [(< x 2)]} | |
"I have the precondition inline! (Clojure default)" | |
(println x " received a number smaller 2")) | |
(defn func2 [y] | |
"I outsourced the precondition in a cool AOP style using dire" | |
(println y "received a number > 41")) | |
(with-precondition #'func2 | |
:not-bigger-than-41 | |
(fn [y] (> y 41))) | |
(supervise #'func2 41) ; => :dire.core/precondition exception for :not-bigger-than-41 | |
(with-precondition! #'func2 | |
:not-bigger-than-41 | |
(fn [y] (> y 41))) | |
(func2 41) ; => :dire.core/precondition exception for :not-bigger-than-41 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment