-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spec2 schema/select distinction #95
Comments
Hi! |
Excellent question! Have been thinking about that a lot and I don't think there is a correct answer for this. Some thoughts:
|
I see you're thinking about this a lot, that's great. So from your POV Once you finish pondering about this it would be nice to get this mentioned in the readme, people (like me) will be comparing this to spec2 and specifically to what lead to the creation of spec2. |
Revisiting this I see you already implemented I'm pondering on one thing: (defn foo [{:keys [x y z] :or {z 1}}]
(if (pos-int? x) (/ y z) 0))
I think for my own data I would model everything as required, that would describe the "shape" of the data and then chop things from that with Does this sound reasonable? I'm also thinking whether there could be an API to capture the 2 operations in 1 swoop, like What about nested maps or a collection of maps? Maybe one could devise a descriptive data-driven DSL to capture the requirements, like {:x :! :y :! :z :?} ; :x :y and optionally :z
{:x :! :y :! :z {:? [{:a ! :b !}]}} ; optional :z where it is a collection of required :a and :b Take this for what it is, a brain dump :) |
a standard query format like EQL might be the way to go. |
I thought about pull syntax, which is close to EQL, before posting, but I don't see a way to describe the required/optional part |
Good point. One though I had in mind was to support transforming key optionality using the map-entry syntax. (mu/assoc-in nil [:a [:b {:optional true}]] int?)
; => [:map [:a [:map [:b {:optional true}] int?]]]] would work also with |
A map is a good idea as it leaves space for future additions. One could want to e.g. define the probability of a key ( |
For a pet-project I implemented schema-select that allows you to create a sub-schema using the spec2 select syntax 1. It has the limitation that it only accepts a map-schema to select from. |
Rich talks extensively about making the distinction about a schema and about the required data within a schema when being used. A person can have many things and only some (different) parts of its data will be required in different functions. That's what the new
select
is about. Is there similar functionality in malli? I see{:optional true}
in an example schema which is exactly what Rich found bad in his first design.The text was updated successfully, but these errors were encountered: