On Thursday, October 5, 2017 at 1:52:47 PM UTC-5, Alex Bezhan wrote: > > > > down votefavorite > <https://stackoverflow.com/questions/46592767/how-do-i-make-custom-clojure-spec-generator#> > > I'm trying to spec the following data structure called Connection: > > {:id "some string" :channel "instance of org.httpkit.server.AsyncChannel" } > > Here is my spec: > > > (defn make-channel [] > (proxy [AsyncChannel] [nil nil] > (toString [] "mock AsyncChannel"))) > (defn channel-gen > [] > (->> (s/gen (s/int-in 0 1)) > > ^^ s/int-in is exclusive on the end of the range, so this will only return 0.
> > (gen/fmap (fn [_] (make-channel))))) > > I don't understand why this is using fmap / gen at all here unless you've cut this down. > > (s/def ::channel (s/spec (::channel-type) > > ^^ just ::channel-type, not (::channel-type) here > > :gen channel-gen)) > > In general, making a generator that re-invokes a function every time is somewhat at odds with how generators work. > > (s/def ::id string?) > (s/def ::connection (s/keys :req-un [::channel ::id])) > (s/fdef make-connection > :args ::channel > :ret ::connection) > > > I think here you probably want to wrap a regex spec around the channel spec (you're specing the args as if you invoked them using apply): (s/fdef make-connection :args (s/cat :ch ::channel) :ret ::connection) > I'm getting the following error and I have no clue what is wrong here: > > clojure.lang.ExceptionInfo: Unable to construct gen at: [] for: > gameserve.ws$make_connection@788ffa19 > clojure.lang.Compiler$CompilerException: clojure.lang.ExceptionInfo: Unable > to construct gen at: [] for: gameserve.ws$make_connection@788ffa19 > #:clojure.spec.alpha{:path [], :form #object[gameserve.ws$make_connection > 0x788ffa19 "gameserve.ws$make_connection@788ffa19"], :failure :no-gen} > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.