Skip to content
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

Shortcut for merging properties #448

Open
helins opened this issue May 14, 2021 · 1 comment
Open

Shortcut for merging properties #448

helins opened this issue May 14, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@helins
Copy link
Contributor

helins commented May 14, 2021

(Originally mentioned on Slack)

In my experience, it is quite common having a schema that is valid for most cases but once in a while, would need some change in properties, like altering :min / :max values or generation with :gen/fmap. Hence, the following would be a very convenient way of quickly reusing a schema like so:

{:int-vec [:vector :int]
 :small-int-vec [:int-vec {:max 3}]}

@ikitommi was asking if modifying children was acceptable or not. I would suggest not. Modifying properties usually do not alter the deeper meaning of the schema itself, whereas altering children typically does:

{:int-vec [:vector :int]
 :double-vec [:int-vec :double]}

In contrast, altering only properties is fairly uncontroversial. By altering, I mean merging given ones with the original ones. I would make a great use of such a feature, do you think other users would as well?

To consider: perf cost, suppose I add another indirection by "extending" :small-int-vec, and yet another one on top of that one, that will be a lot of indirection to resolve. There is a balance to maintain between convenience and performance.

@ikitommi ikitommi added the enhancement New feature or request label May 22, 2021
@eoliphan
Copy link
Contributor

I agree, it sort of 'feels' more natural this way, 'extending' schemas in terms of others. We're using malli more like spec (attr-oriented, mutable registry, etc), enhanced with our own custom properties, and this would be really useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants