This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-12
Channels
- # announcements (1)
- # babashka (79)
- # beginners (165)
- # calva (29)
- # cider (20)
- # clara (3)
- # cljdoc (1)
- # cljs-dev (52)
- # clojure (42)
- # clojure-chicago (5)
- # clojure-europe (48)
- # clojure-germany (1)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-spec (10)
- # clojure-uk (19)
- # clojurescript (50)
- # clojureverse-ops (5)
- # conjure (8)
- # datomic (16)
- # depstar (2)
- # events (1)
- # figwheel-main (23)
- # fulcro (26)
- # girouette (41)
- # graalvm (9)
- # heroku (3)
- # honeysql (10)
- # jackdaw (20)
- # lambdaisland (6)
- # lein-figwheel (1)
- # lsp (34)
- # malli (7)
- # meander (3)
- # music (1)
- # off-topic (14)
- # polylith (7)
- # re-frame (14)
- # reitit (8)
- # reveal (15)
- # ring (3)
- # schema (1)
- # sci (15)
- # shadow-cljs (42)
- # spacemacs (1)
- # startup-in-a-month (12)
- # tools-deps (59)
- # vim (1)
- # xtdb (27)
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 %)))))
(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? ...)
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))