Hi Reid

Yes that's exactly what I was trying to achieve. Thank you very much.

As for the multi-maps. I was simply using the term incorrectly, sorry for 
the confusion.

Thanks once again

On Thursday, 3 July 2014 16:44:29 UTC+2, Reid Draper wrote:
>
> Hi,
>
> I've taken a stab at what I think you want:
>
> (def gen-cache
>   (gen/fmap
>     #(reduce (fn [r m] (merge-with merge r m)) {} %)
>     (gen/vector (gen/fmap
>                   (fn [o]
>                     (let [{:keys [port instr] :as ord} o]
>                       (assoc-in {} [port instr] ord)))
>                   ord-gen))))
>
>
> Instead of using `gen/sample` to create a sequence, I use `gen/vector`. And 
> in order to apply the `reduce` function, I use `gen/fmap`.
>
>
> As an aside, I'm not sure how this is a multi-map. I was under the impression 
> a multi-map was simply a map that can store multiple values in the same key.
>
>
> Reid
>
>
> On Thursday, July 3, 2014 6:06:29 AM UTC-5, cig wrote:
>>
>> 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.

Reply via email to