Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

Hello,

is it possible to get a "closed" generator from a `s/select` form
and/or make it the default in Spec 2?

From the example in the Wiki:

(ns user
  (:require [clojure.alpha.spec :as s]))

(s/def ::id int?)
(s/def ::first string?)
(s/def ::last string?)
(s/def ::user (s/schema [::id ::first ::last ::addr]))

(s/def ::my-user (s/select ::user [::id]))

(s/exercise ::my-user)

This generates users that have more keys than what I selected:

([#:user{:id 0} #:user{:id 0}]
 [#:user{:addr #:user{:city "1"}, :first "O", :id 0}
  #:user{:addr #:user{:city "1"}, :first "O", :id 0}])

I believe it is the same data which the `s/schema` for the `::user`
spec generates. My guess is this just hasn't been implemented yet.

Would it be possible to support this?

1 Answer

0 votes
by

This may be something useful to add eventually. I think you could probably get that now with extra effort of custom generators.

by
Alright, thanks for your answer.
...