clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
seancorfield 2020-08-31T02:23:26.019Z

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

seancorfield 2020-08-31T02:23:39.019600Z

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

cjsauer 2020-08-31T02:26:45.023100Z

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]))

hadils 2020-08-31T02:26:51.023400Z

@seancorfield Sorry my bad

seancorfield 2020-08-31T02:27:08.023500Z

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

seancorfield 2020-08-31T02:27:20.023800Z

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

cjsauer 2020-08-31T02:27:59.024400Z

Oops, didn’t see that. Noted @seancorfield

Petrus Theron 2020-08-31T13:09:33.029300Z

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)]))

johanatan 2020-09-02T04:30:07.034900Z

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.

johanatan 2020-09-02T04:31:45.035100Z

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.