This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-06
Channels
- # babashka (31)
- # beginners (108)
- # calva (6)
- # clj-kondo (62)
- # cljsrn (5)
- # clojure (29)
- # clojure-australia (2)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (7)
- # clojurescript (25)
- # code-reviews (1)
- # datomic (13)
- # deps-new (7)
- # editors (1)
- # emacs (31)
- # figwheel-main (3)
- # garden (4)
- # graalvm (18)
- # helix (10)
- # improve-getting-started (12)
- # jobs (3)
- # lsp (20)
- # malli (12)
- # off-topic (7)
- # polylith (30)
- # re-frame (10)
- # remote-jobs (2)
- # shadow-cljs (18)
- # spacemacs (5)
- # sql (11)
- # tools-deps (10)
- # vim (9)
- # xtdb (1)
I'd like to model a binary tree with a map of the form {:payload 0 :left sub1 :right sub2}
. Here's my spec for now:
(s/def ::binary-tree-2
(s/with-gen
(s/keys :req-un [::payload]
:opt-un [::left ::right])
#(gen/recursive-gen
(fn [f] (gen/let [[val l r] (gen/tuple (s/gen int?) f f)]
(merge
{:payload val}
(when l {:left l})
(when r {:right r}))))
(gen/return nil))))
But this doesn't check that ::left
and ::right
have the correct shape. What should I do instead?I was wondering something similar a while back, and happened to find this: https://deque.blog/2017/05/20/a-clojure-spec-for-generic-binary-trees/ perhaps it might help?