Good afternoon,
like obviously quite a few others on this list I am looking into the
upcoming (and IMHO absolutely great) clojure.spec
During this I noted that the ? macro seems to behave differently from what
I would have naively expected from its documentation (cf.
https://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/?):
? macro
Usage: (? pred-form)
Returns a regex op that matches zero or one value matching
pred. Produces a single value (not a collection) if matched.
In contract, with the namespaces set to
[clojure.spec :as s]
[clojure.spec.gen :as gen]
the following snippet
(s/def ::abcd #{:a :b :c :d})
(gen/sample (s/gen (s/? ::abcd)))
returns a collection of collections:
([] [:c] [:d] [:b] [:b] [] [:a] [] [:d] [])
I would have expected to find either the value itself or nothing, a
behaviour that would seem to me also more practical when composing larger
records with optional elements. However, I might be misreading the
documentation and would be grateful for any clarification
Best regards,
Marc
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.