Fork me on GitHub
#clojure-spec
<
2016-05-30
>
cfleming08:05:00

When s/spec is used to create a new sequential context, I can’t find a way to capture the sequential thing itself.

cfleming08:05:48

For example:

(s/def ::ingredient (s/cat :quantity number? :unit keyword?))
(s/def ::recipe (s/cat :amount (s/spec ::ingredient) :description string?))
(s/conform ::recipe [[2.0 :teaspoon] "Cinnamon"])
=> {:amount {:quantity 2.0, :unit :teaspoon}, :description "Cinnamon"}

cfleming08:05:45

Here, there seems to be no way to capture the [2.0 :teaspoon] vector object if I also want to match its contents.

Alex Miller (Clojure team)11:05:27

@cfleming: you are matching its contents via the cat. If you want to receive the vector as the conformed value you could use coll-of to do a different kind of match or use a conformer to transform the matched result into any arbitrary structure

Alex Miller (Clojure team)11:05:46

Probably the latter is what you want

arohner17:05:44

is there a way to update a map spec? I’d like to say “this fn takes a foo map, and returns a foo map with an extra key added on”. It’d be nice to say (s/def bar (conj foo ::extra-key)), without specifying the keys of the second map explicitly

arohner18:05:01

arg. repl development overwrites instrumentation

moxaj20:05:10

Question: why is the second argument (`retag`) necessary in a multi-spec expression? In the guide, it is the same as the dispatch function, and I don't see any use case where providing a different function would be beneficial. And if it's the same, naming it again is redundant, as it can be retrieved via the public field dispatchFn.

seancorfield20:05:26

As an experiment, I’ve added an optional spec namespace to clojure.java.jdbc: https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc/spec.clj — feedback welcome (the tests attempt to require that ns and instrument clojure.java.jdbc when running tests, so under 1.9.0 the specs are actually checked for all calls in the tests)

potetm21:05:42

Is there any mechanism that will allow you to include possible exceptions as part of a spec?

kovasb22:05:41

How can I spec a function that takes an atom(x), where x conforms to a spec?

kovasb22:05:46

thinking something like atom-of instead of coll-of