https://clojurians.slack.com/archives/C03S1KBA2/p1598836570469900
@hadilsabbagh18 It's a good idea to not cross-post questions here.
You've already gotten a response in another channel on this.
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]))
@seancorfield Sorry my bad
@cjsauer That's the answer they got in the other channel.
Please don't encourage people to cross-post questions here.
Oops, didn’t see that. Noted @seancorfield
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)]))
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
.
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.