Fork me on GitHub
#malli
<
2024-03-31
>
adham09:03:06

Hey all, I again need help understanding why I'm having this error, according to the documentation :* is used for repetition, which works in the normal case (last 2 lines) but in a function schema it does not work as it should and tells me my input needs to be a map when it should be a vector of maps, what is the problem?

radhika09:03:33

args:`[:cat [:* map?] :string]` can be interpreted infix as args:_[map?* string]_ for example `[{} {} {} "foo"]` would be valid args. i.e. args must be sequence beginning with any number of maps and ending with exactly one string value. it seems you intended args:`[:cat [:sequential map?] :string]` instead

3starblaze09:03:39

The :cat inside your function schema is the argument list. So right now your schema accepts variable argument count where last item is a string.

adham09:03:50

> it seems you intended args:`[:cat [:sequential map?] :string]` instead It seems like that, I must have misunderstood the documentation. I'll try this and see how it works.

3starblaze09:03:45

Is it actually the correct solution? I think that the proposed schema cannot match (test-fn "string")

adham09:03:47

> accepts variable argument count So if I understand that correctly, a variable map argument count, so any number of maps and the last argument is a string.

3starblaze09:03:23

This might be the schema (haven't checked) [:=> [:cat [:tuple [:cat [:* :map]] :string]] :any]

adham09:03:22

> Is it actually the correct solution? In this case it should be since my input must have at least one map in a vector (test-fn [{}] "") is what I want to pass.

👍 1
3starblaze09:03:15

does the schema accept (test-fn [] "")?

3starblaze09:03:14

Anyways, to understand the function schema better imagine it like this [:=> args-schema return-schema] So if I have something like [=> [:cat :string :int] :boolean] and call it with (the-fn "foo" 3) then it checks if ["foo" 3] conforms [:cat :string :int] and then checks the return value with return-schema.

👍 1
adham09:03:36

I see, thank you!

👍 1