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
favila 2020-01-27T21:19:00.088400Z

is there any advice for speccing containers, e.g. atoms or delays?

vemv 2020-01-28T16:38:39.095600Z

Say you have a check! function. I normally hook up the :validator to it, but only on *assert*

favila 2020-01-28T17:05:22.095800Z

I went with an fspec instead

favila 2020-01-28T17:05:59.096Z

Most ref types have validators, I forgot about those. you could use s/assert in there

favila 2020-01-28T17:06:20.096200Z

doesn’t help with generation, but there’s manual intervention for generation all the time anyway

favila 2020-01-28T17:06:32.096400Z

delays however don’t have validators

vemv 2020-01-28T17:18:36.096600Z

> doesn’t help with generation, yeah it's a tradeoff :) > delays however don’t have validators yup, as you may know though a custom IDeref impl can be quite thin

favila 2020-01-27T21:19:25.089Z

I’d like to say “takes a delay that returns a thing satisfying some predicate when derefed”

seancorfield 2020-01-27T21:42:32.091100Z

@favila There's no way to do that. You can spec around the code that processes what's inside the container, but you can't spec the container itself.

lilactown 2020-01-27T21:44:08.091600Z

atoms do have validator functions that you can pass in on instantiation I think?

alexmiller 2020-01-27T21:49:28.091800Z

they do

alexmiller 2020-01-27T21:49:47.092100Z

but carefully consider the costs there