Skip to content

Instantly share code, notes, and snippets.

@fogus
Created December 21, 2009 20:32
Show Gist options
  • Save fogus/261215 to your computer and use it in GitHub Desktop.
Save fogus/261215 to your computer and use it in GitHub Desktop.
(defn constrained-fn [f x]
{:pre [(pos? x)]
:post [(= % (* 2 x))]}
(f x))
(constrained-fn #(* 2 %) 2)
;=> 4
(constrained-fn #(float (* 2 %)) 2)
;=> 4.0
(constrained-fn #(* 3 %) 2)
;=> java.lang.Exception: Assert failed: (= % (* 2 x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment