ClojureDocs

Nav

Namespaces

or

  • (or & key-pred-forms)
Takes key+pred pairs, e.g.
 (s/or :even even? :small #(< % 42))
 Returns a destructuring spec that returns a map entry containing the
key of the first matching pred and the corresponding value. Thus the
'key' and 'val' functions can be used to refer generically to the
components of the tagged return.
2 Examples
(require '[clojure.spec.alpha :as s])

(let [spec (s/or :n number? :b boolean?)]
  [(s/conform spec 1)
   (s/conform spec true)
   (s/conform spec "str")])
;; => [[:n 1] [:b true] :clojure.spec.alpha/invalid]
(require '[clojure.spec.alpha :as s])

(s/def ::type-hinted-destructure
  (s/coll-of (s/or :hinted (s/cat :symbol symbol?
                                  :separator #(= :- %)
                                  :schema any?)
                   :not-hinted (s/cat :symbol symbol?))
             :kind vector?))

(s/conform ::type-hinted-destructure
           '[[first :- string?]  ; `[first :- string?]` not `first :- string?`
             [last]])
;; [[:hinted {:symbol first, :separator :-, :schema string?}] [:not-hinted {:symbol last}]]
See Also

Takes key+pred pairs, e.g. (s/alt :even even? :small #(< % 42)) Returns a regex op that return...

Added by ryoakg

A soft limit on how many times a branching spec (or/alt/*/opt-keys/multi-spec) can be recursed thr...

Added by bfontaine

Takes predicate/spec-forms, e.g. (s/and even? #(< % 42)) Returns a spec that returns the confo...

Added by bfontaine
0 Notes
No notes for or