Permalink
Browse files

Added associative function constraints

  • Loading branch information...
1 parent a18f806 commit 1bcd09d89857fc1eafd57a574f30b8cf74f12e55 @fogus fogus committed Mar 2, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/main/clojure/clojure/core/contracts/constraints.clj
@@ -162,3 +162,23 @@
{:contract ~chk})))
~name)))
+(defn- apply-contract
+ [f]
+ (if (:hooked (meta f))
+ f
+ (with-meta
+ (fn [m & args]
+ (if-let [contract (-> m meta :contract)]
+ ((partial contract identity) (apply f m args))
+ (apply f m args)))
+ {:hooked true})))
+
+(when *assert*
+ (alter-var-root (var assoc) apply-contract)
+ (alter-var-root (var dissoc) apply-contract)
+ (alter-var-root (var merge) apply-contract)
+ (alter-var-root (var merge-with) (fn [f] (let [mw (apply-contract f)] (fn [f & maps] (apply mw f maps)))))
+ (alter-var-root (var into) apply-contract)
+ (alter-var-root (var conj) apply-contract)
+ (alter-var-root (var assoc-in) apply-contract)
+ (alter-var-root (var update-in) apply-contract))

0 comments on commit 1bcd09d

Please sign in to comment.