Fork me on GitHub
#clojure-spec
<
2019-04-06
>
gfredericks02:04:56

set! in that context, used as a past tense verb, is pronounced "set-bung"

ikitommi12:04:52

Is there a way to construct the selection in s/select programmatically? e.g. have the selection somewhere as data (in db, edn, etc) and make a select out of it at runtime.

ikitommi12:04:17

same for s/schema

ikitommi12:04:20

also, could the selection syntax allow something special that effects the whole keyset, not present an individual key. Could be just a function or a special Protocol.

(s/def ::passwords-must-equal #(= (:password1 %) (:password2 %)))

(s/select ::user [::user ::password1 ::password2 ::passwords-must-equal]) 
;; or
(s/select ::user [::user ::password1 ::password2 #(= (:password1 %) (:password2 %))]) 

ikitommi13:04:59

… if that special keyset-validator would be implemented with a protocol, it would be great to have a function which takes both the spec and the value as arguments, so one could easily write something like ::closed-keyset: the function could extract the list of defined keys from the spec argument and use that to verify that the value doesn’t have any extra keys. And if the validation could return the ::s/problems instead of just ::s/invalid, it would be easy to write those, e.g. no need to write separate explain too.

👍 8
metametadata13:04:51

+1, would be nice to have something like that. because currently relying on forms, macros or low-level *-impl helpers is quite cumbersome (e.g. see my attempt at implementing merge-able closed keys spec with user-friendly explain here: https://groups.google.com/d/msg/clojure/duY3ojPwPYo/Wgvk9PsaCAAJ)

👀 4
ikitommi14:04:12

I too have almost mergeable closed specs with Spec1, but next hurdle is to get deep-mergeable specs...

Alex Miller (Clojure team)17:04:22

You have two routes to programmable specs in spec 2

Alex Miller (Clojure team)17:04:40

You can make forms, and call spec*

Alex Miller (Clojure team)17:04:03

Or you can make your own syntax that wraps something with defop

Alex Miller (Clojure team)17:04:30

Or actually third option is making your own spec instance from scratch but that’s a much heavier lift

Alex Miller (Clojure team)17:04:39

We are evaluating support for preds in specs - tbd

Alex Miller (Clojure team)17:04:11

But we are working on another kind of checking for closed specs