Fork me on GitHub
#clojure-spec
<
2017-01-27
>
wei03:01:35

could someone point me to some real world examples of conform? I have a hunch that it would be very useful for me, especially with specs like s/or, but I haven’t found the output to be especially easy to adapt, for example in a cond statement.

wei04:01:18

here’s an example that I think is overly verbose: https://gist.github.com/yayitswei/fc60da9271452716ae2a197c945a4b3e, would appreciate any tips on trimming this down

luxbock07:01:01

is there some existing function that gives me the same value that the predicates/specs in :fn receive?

luxbock07:01:20

I am assuming no, but it's probalby not too difficult to create

luxbock08:01:46

this seems to work

nblumoe12:01:41

Hey, what are uses for the :opts key spec on maps? As additional keys are allowed anyways and all present keys are being validated even if they are not in the explicit spec there does not seem to be any relevance for validation. Is it for generation? Something else I’m missing?

schmee13:01:00

nblumoe AFAIK it’s for generation and as documentation

nblumoe13:01:39

The guide says this: “ When conformance is checked on a map, it does two things - checking that the required attributes are included, and checking that every registered key has a conforming value. We’ll see later where optional attributes can be useful. Also note that ALL attributes are checked via keys, not just those listed in the :req and :opt keys. Thus a bare (s/keys) is valid and will check all attributes of a map without checking which keys are required or optional.” I do not know what “We’ll see later where optional attributes can be useful” is referring to

Alex Miller (Clojure team)14:01:17

They are used in generators (as well as serving as doc)

Alex Miller (Clojure team)14:01:44

@luxbock the :fn spec receives a map {:args …, :ret …} where the values are the conformed values of the args and ret specs. you don’t need that get-fspec-attr - you can call (s/get-spec sym) to get the fspec and that supports ILookup, so you can (:args (s/get-spec sym)) to get (for example) the args spec.

luxbock14:01:57

@alexmiller: thanks, yeah figured there might have been a better way