Is it possible to validate multiple functions against the same function schema?

15 views
Skip to first unread message

Rovanion Luckey

unread,
May 8, 2017, 7:56:34 AM5/8/17
to Plumbing and Graph: the Clojure utility belt
 The Leiningen project.clj files have a key :checkout-deps-shares which holds a vector of functions which take a project map as their argument and returns one or more paths. Say we want to create a specification for the values held in this field, how would we go about it?

The example data given by leiningen for the feild is:

 :checkout-deps-shares      [:source-paths :test-paths
                             
(fn [p] (str (:root p) "/lib/dev/*"))]

A vector of three functions which take a map and return one or more strings.

I've understood from previous conversations here on the list that this may be a bit of a problem, that there are these detached function definitions declared with => but they can't be used for validation. So I just wanted to make sure that there is no way to validate functions that I don't declare myself. And if it isn't true, ask about how it's done.

Jason Wolfe

unread,
May 8, 2017, 12:42:14 PM5/8/17
to Rovanion Luckey, Plumbing and Graph: the Clojure utility belt
As you say, you can write a schema with =>, but it won't be validated.  The function does not have the type information, so there is no way to validate it without actually wrapping it so that validation happens when it is called in the future.  Schema does not do this for you out of the box, but you could do it manually by mapping over the functions and wrapping them in a schematized fn -- or I suppose you could even use coercion to do that automatically.

Best, Jason

--
You received this message because you are subscribed to the Google Groups "Plumbing and Graph: the Clojure utility belt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prismatic-plumbing+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages