I would assume it’s a “maximal munch” strategy at play here: (spec/* string?) will only match one string in your input but (spec/* identity) will match all three elements so it “wins” as the best match.
Perhaps :default (spec/* (complement string?)) will do what you need? (depending on exactly what you want to happen if you aren’t matching at least one string?) Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ________________________________ From: clojure@googlegroups.com <clojure@googlegroups.com> on behalf of J <jvidev...@gmail.com> Sent: Thursday, August 2, 2018 6:31:15 AM To: Clojure Subject: Order of preds in clojure.spec/alt Hi there, right now i am using spec to match some input data with something like this (require '[clojure.spec.alpha :as spec]) (spec/conform (spec/cat :stuff (spec/alt :strings (spec/* string?) ;:default (spec/* identity) ) :rest (spec/* identity)) ["some string" 2 2]) => {:stuff [:strings ["some string"]], :rest [2 2]} But if i add a "default" to alt it returns something unexpected (spec/conform (spec/cat :stuff (spec/alt :strings (spec/* string?) :default (spec/* identity)) :rest (spec/* identity)) ["some string" 2 2]) => {:stuff [:default ["some string" 2 2]]} The docs https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html#clojure.spec.alpha/alt says: Returns a regex op that returns a map entry containing the key of the first matching pred and the corresponding value. I would expect that (spec/* string?) is the first matching pred and not the (spec/* identitiy). Is this behavior correct? Thanks J -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com<mailto:clojure+unsubscr...@googlegroups.com>. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.