Hi I have been trying to build a test.check generator for a multi map, without much success. I have a generator which generates ordinary maps:
(def ord-gen (gen/fmap (partial zipmap [:port :instr :qty]) (gen/tuple (gen/not-empty gen/string-alpha-numeric) (gen/not-empty gen/string-alpha-numeric) (gen/frequency [[9 gen/pos-int] [1 gen/neg-int]])))) (gen/sample ord-gen 3) ;; => ({:qty 0, :instr "X4", :port "re"} {:qty 0, :instr "v", :port "8"} {:qty 1, :instr "3A", :port "7"}) However, I would like to merge this sequence of individual maps into a multi-map of the form: {"re" { "X4" {:qty 0, :instr "X4", :port "re"}}, "8" { "v" {:qty 0, :instr "v", :port "8"}}, "7" { "3A" {:qty 1, :instr "3A", :port "7"}}} The closest I have gotten to achieving this is by realising the intermediate steps: (def gen-cache (->> (gen/fmap (fn [o] (let [{:keys [port instr] :as ord} o] (assoc-in {} [port instr] ord))) ord-gen) (gen/sample) (reduce (fn [r m] (merge-with merge r m)) {}) (gen/return))) However, this returns the same value constantly (I am aware that, that is what gen/return is supposed to do, however, I can not get much else working for me). I would Ideally like to bind the ord-gen into the gen-cache generator. Any help would be very appreciated. -- 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.