Fork me on GitHub
#clojure-spec
<
2020-08-31
>
cjsauer02:08:45

The fact that you’re destructuring the key doesn’t change the fact that budget-item-type simply accepts a map. Assuming you have a spec for :transaction/amount, your args spec would be something like (s/cat (s/keys :req-un [:transaction/amount]))

seancorfield02:08:08

@U6GFE9HS7 That's the answer they got in the other channel.

seancorfield02:08:20

Please don't encourage people to cross-post questions here.

cjsauer02:08:59

Oops, didn’t see that. Noted @seancorfield

seancorfield02:08:26

@hadilsabbagh18 It's a good idea to not cross-post questions here.

seancorfield02:08:39

You've already gotten a response in another channel on this.

Petrus Theron13:08:33

How to constrain the size of two dependent coll-of specs, A & B so that (<= (count (concat A B)) 40)? AFAICT, I need to use g/bind to constrain the :max-count of B's sample based on the length of A, but I'm having some trouble getting this to work in Spec2. @alexmiller you mentioned you are considering basic logic resolution. It would be awesome if it was possible to do something like:

(let [a (s/coll-of digit? :max-count 30)
      b (s/coll-of digit? :max-count (- 40 (s/count a))]
  (g/fmap (fn [a b] (apply str a ":" b) [(s/gen a) (s/gen b)]))

johanatan04:09:07

I always use gen/let for this sort of thing. You can use it just like a normal let except with generators on the rhs and generated values bound to the lhs. if you need a regular value you can use a gen/return to effectively raise them to that level such that both regular values and generated values can be bound in the same gen/let.

johanatan04:09:45

in this particular case, you could generate an int with int-in 1 40 and then compute a second int-in 40 - the first. then use the two ints as exact size parameters to your collection generators.