what would be the most idiomatic way to spec a graph structure? I would want something around (`graph` is the loom library):
(s/def ::my-graph
(s/and
graph/directed?
#(not= :cljs.spec.alpha/invalid (s/conform (s/coll-of ::my-node) (graph/nodes %)))))
but I find that predicate quite cumbersome to write
(s/def ::my-graph
(s/and
graph/directed?
#(s/valid? (s/coll-of ::my-node) (graph/nodes %))))
is a bit better. Is there anything better still?@meditans not an answer to your question, but in general: instead of = :cljs.spec.alpha/invalid
use (s/invalid? ...)
I think you should be able to leave out s/valid?
and just pass a spec
but how would I also invoke graph/nodes
?
What does your graph data structure look like? Is it some kind of custom data type, and therefore it requires the graph/nodes
accessor?
@meditans If it's just a map, which is preferred in most situations, you can just spec a :graph/nodes
key while also getting all the benefits of spec for your other graph metadata
the data structure is the one in the loom
library. (graph/nodes %)
is the invocation of the function that gives the nodes back
One potential option is to use a conformer in your s/and
to handle the conversion into your specable form:
https://clojuredocs.org/clojure.spec.alpha/conformer
(s/and graph/directed?
(s/conformer graph/nodes)
(s/coll-of ::my-node))