Fork me on GitHub
#test-check
<
2017-04-16
>
nberger02:04:26

@jfntn one way is using gen/let:

(defn gen-with-index-and-count-using-let
    "Return a generator that will return tuples of:
    [<value from coll-gen>
    [<valid index in coll>
    <count within bounds of index to end of coll>]."
    [coll-gen]
    (gen/let [coll coll-gen
              index (gen/choose 0 (max 0 (dec (count coll))))
              bounded-count (gen/choose 0 (- (count coll) index))]
      [coll [index bounded-count]]))

nberger02:04:57

makes it much easier to read to my eyes 🙂

jfntn05:04:18

Ooh monads 😄 very nice, didn’t know about this let, thank you

nberger18:04:59

Hehe yeah, it's a macro that takes those bindings and transform them to use gen/bind so it's probably generating something similar to your original generator