or

added

ns
clojure.spec

type
macro

(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.

                ;; contrasting `or` and `alt` (which works on sequence elements)
user=> (s/conform (s/or :num number? :key keyword?) 3)
[:num 3]

user=> (s/conform (s/or :num number? :key keyword?) [3])
:clojure.spec.alpha/invalid

;; compare this to `alt`:
user=> (s/conform (s/alt :num number? :key keyword?) 3)
:clojure.spec.alpha/invalid

user=> (s/conform (s/alt :num number? :key keyword?) [3])
[:num 3]