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
danm 2021-04-21T08:18:24.093600Z

Ahoy! Is there any way to generate a spec for an anonymous function without using s/fspec? Or without s/fspec generating data to test the function with? We've got a pattern where a callback is passed into a function, and we want to validate that the callback conforms to the expected function 'shape'/arity. As I understand it we can't use s/fdef, because at the point we get the callback (as an arg to our function) it's not bound to a symbol, which s/fdef requires as the first arg. Our callback function may be side effecting/have state (store some of the callback results in an atom for later reference), so if we use s/fspec then we do get an error if the callback doesn't have the right arity, but our state also gets corrupted with all the junk data that s/fspec generated to test the function.

alexmiller 2021-04-21T12:52:44.094200Z

You can just spec it as ifn?

alexmiller 2021-04-21T12:53:24.094900Z

It won’t check the “shape” then