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
2019-12-29T07:17:44.041100Z

Hi, everyone is using spec/assert in production a good practice ? I want to produce detailed exceptions like spec/assert does for mismatches but do not want to allow some erroneous code to be able to disable the asserts by calling spec/check-asserts . Am I getting something wrong ? Thanks a alot

vlaaad 2019-12-29T08:25:59.041200Z

I use spec/assert in dev and custom function which is a mostly a valid? + throw in production

2019-12-29T11:01:33.041400Z

Hi @vlaaad but this way I won't have descriptive exceptions like those thrown by spec/assert. Am I right ?

vlaaad 2019-12-29T11:13:11.042600Z

@ho0man that's configurable by you. when I throw, I store spec/explain-data as error data and use spec/explain-str as error message — all the bits are there

2019-12-29T11:18:54.045Z

Thanks a lot @vlaaad, I didn’t know about them Thanks

unbalanced 2019-12-29T14:34:42.047300Z

Curious if there's a way in spec to do the following:

{:a (s/coll-of int?)
 :b (s/coll-of int? :count <3 times (count (:a this))>)}
or for that matter is it even possible to specify multiples instead of :count in coll-of?

unbalanced 2019-12-29T14:36:27.048100Z

(need 3 coordinates per vertex ID, ideally, is what I'm going for)

2019-12-29T15:38:10.050600Z

@goomba Any predicate function is a spec, so you could use s/and to combine a spec like you typed above (but without the bit about counts) with a predicate function checking that the counts are valid. If you want generation to work, you'll likely want to provide a custom generator that does something like generate a map with the proper types and then truncate things to make the counts work out.

👍 2
unbalanced 2019-12-29T15:45:10.051300Z

ahhh okay thank you! I'll look into this.