Skip to content

Instantly share code, notes, and snippets.

@st
Last active July 15, 2016 09:29
Show Gist options
  • Save st/ff105f4da5bc47e76fece033aad23b22 to your computer and use it in GitHub Desktop.
Save st/ff105f4da5bc47e76fece033aad23b22 to your computer and use it in GitHub Desktop.
first steps with clojure.spec
user=> (require '[clojure.spec :as s])
nil
user=> (s/def ::big #(< 10 %))
:user/big
user=> (s/valid? ::big 10)
false
user=> (s/valid? ::big 100)
true
user=> (s/def ::big-or-even (s/or ::big even?))
:user/big-or-even
user=> (s/valid? ::big-or-even 100)
true
user=> (s/valid? ::big-or-even 101)
false
;; why ?
user=> (s/explain ::big-or-even 101)
val: 101 fails spec: :user/big-or-even at: [:user/big] predicate: even?
;; why o why ?
@st
Copy link
Author

st commented Jul 15, 2016

(s/def ::big-or-even (s/or :big ::big :even even?))
;; is the correct way to describe a s/or (specs must be tagged) 
;; thanks to @mamuninfo2 and @puredanger 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment