Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (s/def ::obj-type #{:a :b})
  2. (s/def ::attribute int?)
  3.  
  4. (s/def ::base-obj (s/keys :req-un [::obj-type ::attribute]))
  5.  
  6. (s/def ::only-in-a #{"a"})
  7. (s/def ::only-in-b #{"b"})
  8. (defmulti obj-type :obj-type)
  9. (defmethod obj-type :a [_]
  10.   (s/merge ::base-obj (s/keys :req-un [::only-in-a])))
  11. (defmethod obj-type :b [_]
  12.   (s/merge ::base-obj (s/keys :req-un [::only-in-b])))
  13.  
  14. (s/def ::obj (s/multi-spec obj-type :obj-type))
  15.  
  16. (s/exercise ::obj 20 {::obj-type #(gen/return :a)})
  17. ; returns maps with both ":a" and ":b"
  18. (s/exercise ::base-obj 20 {::obj-type #(gen/return :a)})
  19. ; returns maps with only ":a"
  20. ; why does the generator work in the second example?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement