-
Notifications
You must be signed in to change notification settings - Fork 204
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
mx/defn and malli.destructure/parse unexpected handling of seqexps #1005
Comments
Yes, this is because of the auto-flattening of sequence schemas so it's a feature. You can escape it by wrapping it with non-sequence schema like (mx/defn ^:malli/always f [xs :- [:schema [:* :int]]]
(malli.core/validate [:* :int] xs)) or just use non-sequential like (mx/defn ^:malli/always f [xs :- [:vector :int]]
(malli.core/validate [:* :int] xs)) I don't think we should change this, maybe just document this into https://github.com/metosin/malli/blob/master/docs/function-schemas.md. PR most welcome on this. |
would you have time to document this? e.g. PR most welcome |
The auto flattening is good in general but maybe not what's wanted for parsing arg vectors? I can't think of a situation where I'd want it, but I might be lacking imagination :)
Would it be preferable to document it, or to insert the wrapping :schema automatically when using `malli.destructure/parse`?
Happy to have a go at either when I have a minute.
|
No auto-wrapping now, flattening is needed to describe Varargs. Thanks! |
If I write
I would expect
(f 1)
to throw an except and(f [1])
to return true.I think this is because the schemas for the arguments are combined using
[:cat ...]
and[:cat [:* :int]]
'flattens' the expression, so[[1]]
is not valid for[:cat [:* :int]]
. In this simple case the args schema should be something like[:tuple [:* :int]]
for which[[1]]
is valid.Of course this is not so simple for varargs.
The text was updated successfully, but these errors were encountered: