Fork me on GitHub

@alexmiller just curious: any progress on spec2 lately?

👍 2

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/keys :req-un [::payload]
            :opt-un [::left ::right])
      (fn [f] (gen/let [[val l r] (gen/tuple (s/gen int?) f f)]
                {: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 added more predicates with s/and, but I still wonder if there's a better way

Bobbi Towers20:09:24

I was wondering something similar a while back, and happened to find this: perhaps it might help?