Skip to content

Commit

Permalink
Reorder README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcompton committed Mar 4, 2019
1 parent fa111a1 commit c842ace
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@

defn-spec lets you create Clojure Specs inline with your `defn`. The syntax (and implementation) has been borrowed from [Schema](https://github.com/plumatic/schema), so if you've used that before, this should be very familiar.

Instead of writing your `fdef` separately from your `defn`:
You can define your argument and return specs inline with your `defn`:

```clj
(ns my.ns
(:require [net.danielcompton.defn-spec.alpha :as ds]
[clojure.spec.alpha :as s]
; ...
))

;; Predicate definitions elided for brevity
(s/def ::instant instant?)
(s/def ::zone-id zone-id?)
(s/def ::zoned-date-time zoned-date-time?)

(ds/defn to-zoned-dt :- ::zoned-date-time
[instant :- ::instant
zone-id :- ::zone-id]
(ZonedDateTime/ofInstant instant zone-id))
```

Instead of writing your `fdef` separately from your `defn`:

```clj
(defn to-zoned-dt
[instant zone-id]
(ZonedDateTime/ofInstant instant zone-id))
Expand All @@ -21,20 +36,6 @@ Instead of writing your `fdef` separately from your `defn`:
:ret ::zoned-date-time)
```

You can define your argument and return specs inline with your `defn`:

```clj
(ns my.ns
(:require [net.danielcompton.defn-spec.alpha :as ds]
; ...
))

(ds/defn-spec to-zoned-dt :- ::zoned-date-time
[instant :- ::instant
zone-id :- ::zone-id]
(ZonedDateTime/ofInstant instant zone-id))
```

## Usage

The basic syntax is the same as `clojure.core/defn`, but you can optionally add 'spec hints' with `:-` to any of the arguments and the return value. Any valid spec can be used, e.g. functions, sets, registered spec identifiers.
Expand Down

0 comments on commit c842ace

Please # to comment.