Fork me on GitHub
#clojure-spec
<
2017-09-05
>
Avichal09:09:19

Hello, I am trying to spec some higher order functions using fdef and fspec For eg:

(s/fdef adder
  :args (s/cat :x number?)
  :ret (s/fspec :args (s/cat :y number?)
                :ret number?)
  :fn #(= (-> % :args :x) ((:ret %) 0)))
is it possible to get the value of argument x inside the spec of the inner function which is returned ?

fothaggenda14:09:23

Hello there! Quick question: is it possible to create an "inline" s/keys inside a s/cat in fdefs? Like:

(s/fdef something :args (s/cat :first-argument (s/keys :req-un [::a ::b ::c])))

fothaggenda14:09:45

😞 Ok, thank you!

Alex Miller (Clojure team)14:09:08

or wait, maybe? what are you trying to do?

Alex Miller (Clojure team)14:09:40

if you’re matching varargs in a function

fothaggenda14:09:54

Hmmm, I'll check that out 😃

Alex Miller (Clojure team)14:09:19

and even my prior answer is wrong - you can use s/keys there (I just don’t think it’s what you want)

Alex Miller (Clojure team)14:09:45

are you taking a map or a series of key/value options in something?

fothaggenda14:09:55

Odd; I tried that way before and my generative test exploded

fothaggenda14:09:58

I'm taking a map

Alex Miller (Clojure team)14:09:08

oh, then you should be fine with the above

Alex Miller (Clojure team)14:09:57

if you want to test it, run (s/exercise (s/cat :first-argument (s/keys :req-un [::a ::b ::c])) 1000) - that’s basically what you’re getting with a generative test on something

fothaggenda14:09:44

Nice catch, I'll inspect this way

Alex Miller (Clojure team)14:09:01

often pushing that out to 1000 samples reveals more :)

Alex Miller (Clojure team)14:09:33

if a/b/c are big colls, that can provoke some problematic samples - bounding their size often helps

fothaggenda14:09:21

Actually that's not the case, in my scenario ::a, ::b and ::c are just very specific definitions, but I got your point

arohner18:09:41

are there any projects for associating docstrings with spec definitions?

Alex Miller (Clojure team)18:09:54

we will eventually get around to implementing it in spec, just kinda far down the list atm