You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 :schema:
(mx/defn ^:malli/always f [xs :- [:schema [:*:int]]]
(malli.core/validate [:*:int] xs))
or just use non-sequential like :vector:
(mx/defn ^:malli/always f [xs :- [:vector:int]]
(malli.core/validate [:*:int] xs))
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.
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: