Fork me on GitHub
#clojure-spec
<
2021-08-15
>
vlaaad19:08:48

s/* wrapping s/alt conform gives a vector of tuples (expected):

(s/conform (s/* (s/alt :strs (s/+ string?)
                         :ints (s/+ int?)))
             ["a" "x" 1 2])
=> [[:strs
     ["a" "x"]]
    [:ints
     [1 2]]]
s/+ wrapping s/alt conform gives a vector with tuple and a vector of tuples (unexpected):
(s/conform (s/+ (s/alt :strs (s/+ string?)
                         :ints (s/+ int?)))
             ["a" "x" 1 2])
=> [[:strs
     ["a" "x"]]
    [[:ints
      [1 2]]]]

dgb2319:08:58

so weird when you look at:

(s/conform (s/+ (s/alt :strs (s/+ string?)
                       :ints (s/+ int?)))
           ["a" "x" 1 2 "b" "c" 4 5])

vlaaad20:08:26

fixed formatting

Alex Miller (Clojure team)21:08:01

I'm not seeing what's unexpected here, can you describe?

vlaaad05:08:30

Second element of second result unnecessary wrapped in a vector

vlaaad21:08:04

given (s/def ::foo (s/* any?)) , shouldn't (s/regex? ::foo) also return true?

seancorfield21:08:41

That operates on the (internal) spec form I believe, not on spec names.

seancorfield21:08:11

Use (s/regex? (s/get-spec ::foo)) @vlaaad

seancorfield21:08:17

dev=> (s/def ::bar string?)
:dev/bar
dev=> (s/def ::foo (s/* any?))
:dev/foo
dev=> (s/regex? (s/get-spec ::bar))
nil
dev=> (s/regex? (s/get-spec ::foo))
{:clojure.spec.alpha/op :clojure.spec.alpha/rep, :p2 #object[clojure.core$any_QMARK_ 0x18d396eb "clojure.core$any_QMARK_@18d396eb"], :splice false, :forms clojure.core/any?, :id #uuid "9d09bd34-f6f5-4ee6-a69f-4e84a312b5d0", :p1 #object[clojure.core$any_QMARK_ 0x18d396eb "clojure.core$any_QMARK_@18d396eb"], :ret [], :clojure.spec.alpha/name :dev/foo}