ClojureDocs

Nav

Namespaces

alt

  • (alt & key-pred-forms)
Takes key+pred pairs, e.g.
 (s/alt :even even? :small #(< % 42))
 Returns a regex op 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/alt :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/* (s/alt :hinted (s/cat :symbol symbol?
                             :separator #(= :- %)
                             :schema any?)
              :not-hinted (s/cat :symbol symbol?))))

(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/or :even even? :small #(< % 42)) Returns a destructuring spec th...

Added by ryoakg
0 Notes
No notes for alt