Liking cljdoc? Tell your friends :D

defn-spec

A Clojure(Script) wrapper around defn that adds checking to a function's args and/or return value via assertions.

This fork of defn-spec always checks funtion's args and/or return value. It also disallows any provided metadata keys that aren't ret and args to avoid typos.

Clojars Project

Usage

You use defn-spec in the same way you would use defn:

(require '[clojure.spec.alpha :as s])
(require '[defn-spec.core :as ds])

(ds/defn-spec my-inc
  [x]
  (inc x))

This time with specs:

(ds/defn-spec my-inc
  {::ds/args (s/cat :x int?)
   ::ds/ret  nat-int?}
  [x]
  (inc x))

Tests

  • Clojure: lein test
  • Clojurescript: lein doo <js-env> (ex: lein doo phantom)

License

Copyright © 2018 Provisdom

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Can you improve this documentation? These fine people already did:
Kenny Williams & Frozenlock
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close