From c842acebc761c2d6bdca721383626cb9dfd55a05 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Tue, 5 Mar 2019 12:06:07 +1300 Subject: [PATCH] Reorder README examples --- README.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5d1dbd9..e5aa8bd 100644 --- a/README.md +++ b/README.md @@ -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)) @@ -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.