Skip to content

Instantly share code, notes, and snippets.

@andradefil
Created December 19, 2025 12:52
Show Gist options
  • Select an option

  • Save andradefil/c25338c7e3d39fb6c331ea5333dffb94 to your computer and use it in GitHub Desktop.

Select an option

Save andradefil/c25338c7e3d39fb6c331ea5333dffb94 to your computer and use it in GitHub Desktop.
gen and select
(require '[clojure.test.check.generators :as tgen])
(def gen-vals-and-select
(tgen/bind
gen-db-vals
(fn [db-vals]
(def db-vals db-vals)
(if (seq db-vals)
(tgen/let [nth1 (tgen/choose 1 3)
nth2 (tgen/choose 1 3)
sz1 (tgen/choose 1 (count db-vals))
sz2 (tgen/choose 1 (count db-vals))]
[(into {} (take sz1 (take-nth nth1 db-vals)))
(into {} (take sz2 (take-nth nth2 db-vals)))])
(tgen/return [{} {}])))))
(def gen-vals-and-select2
(tgen/bind
gen-db-vals
(fn [vs]
(if (seq vs)
(tgen/return
[(into {} (tgen/vector-distinct
(tgen/elements vs)))
(into {} (tgen/vector (tgen/elements vs)))])
(tgen/return [{} {}])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment