Skip to content

Instantly share code, notes, and snippets.

@MichaelDrogalis
Created January 12, 2013 00:03
Show Gist options
  • Save MichaelDrogalis/4515066 to your computer and use it in GitHub Desktop.
Save MichaelDrogalis/4515066 to your computer and use it in GitHub Desktop.
(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