Fork me on GitHub
#clojure-spec
<
2017-12-08
>
triss13:12:56

Hi all… anyone got a nicer way of doing this?

(defn cat-specs
  "Takes a spec and finds the highest level 's/cat' from it and extracts the
  specs of the values it matches."
  [spec]
  (->> (s/form spec)
       (tree-seq seq? identity)
       (filter seq?)
       (filter #(= 'clojure.spec.alpha/cat (first %)))
       (first)
       (rest)
       (partition 2)
       (map second)))

souenzzo14:12:31

(defn cat-specs
  "Takes a spec and finds the highest level 's/cat' from it and extracts the
  specs of the values it matches."
  [spec]
  (->> (s/form spec)
       (s/conform (s/cat :op '#{clojure.spec.alpha/cat}
                         :args (s/* (s/cat :name keyword?
                                           :value any?))))
       :args
       (map :value)))
Some like this. This issue will help https://dev.clojure.org/jira/browse/CLJ-2112

triss11:12:14

Fantastic thankyou! Apologies I just got round to understanding this