Clojurians
#test-check
<
2017-01-16
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

danstone15:01:19

I want to write a generator that zipmaps values in coll-a to values in coll-b, but with the restriction that each entry in coll-a will be present in keys of the resulting map. Is this possible?

danstone15:01:02

I've got something like this

(let [a [1 2 3]
           b [:foo :bar]]
       (gen/fmap (partial apply zipmap)
                 (gen/tuple
                   (gen/shuffle a)
                   (gen/return (cycle b)))))

danstone15:01:18

not sure if there is a better way to do it

gfredericks16:01:47

how about (let [a [1 2 3], b [:foo :bar]] (gen/let [vals (gen/vector (gen/elements b) (count a))] (zipmap a vals))) @danstone

danstone16:01:03

Thats great - thanks @gfredericks