Contracts programming for Clojure.
Project status: Inactive. The author (fogus) considers this library to have been superseded by clojure.spec.
Based on Trammel and clojure-contracts.
Latest stable release: 0.0.7
CLI/deps.edn dependency information:
org.clojure/core.contracts {:mvn/version "0.0.7"}
Leiningen dependency information:
[org.clojure/core.contracts "0.0.7"]
Maven dependency information:
<dependency>
<groupId>org.clojure</groupId>
<artifactId>core.contracts</artifactId>
<version>0.0.7</version>
</dependency>
(use 'clojure.core.contracts)
(def secure-doubler
(with-constraints
(fn [n] (* 2 n))
(contract doubler
"ensures doubling"
[x] [number? => (= (* 2 x) %)]
[x y] [(every? number? [x y])
=>
(= (* 2 (+ x y)) %)])))
(secure-doubler 10)
;=> 20
Refer to docstrings in the clojure.core.contracts namespace.
See also the wiki for some documentation and examples.
defconstrainedrecordcontract, with-constraints and provide from TrammelCopyright (c) Rich Hickey, Michael Fogus and contributors, 2023. All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound bythe terms of this license. You must not remove this notice, or any other, from this software.
Can you improve this documentation? These fine people already did:
Alex Miller, fogus, Sean Corfield, Fogus & Jakub HolyEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |