Fork me on GitHub
#malli
<
2021-05-06
>
mike_ananev12:05:20

what is the difference between :or and :alt ?

mike_ananev12:05:00

found in docs, :alt is for spec inside seq

đź‘Ť 2
mike_ananev12:05:37

@ikitommi how to define string constant in map spec? e.g version api is a constant

mike_ananev13:05:05

[:enum "v1.0.0"] ?

mike_ananev13:05:22

is there other ways?

mike_ananev13:05:52

and why sets are not supported as spec definition? I cannot put

[:abc #{1 2 3}]
in map spec

ikitommi13:05:05

[:= "v1.0.0"] or [:enum "v1.0.0"], both work.

ikitommi13:05:34

#{1 2 3} doesn’t work as we didn’t want to reserver too much clojure syntax for special purposes. There is a hook to add support for that in the user space, but not documented as it’s not recommended.

ikitommi13:05:09

also, now I think adding a shortcut syntax for regexps was not a good idea.

ikitommi13:05:56

why? there is a cljs compiler warning about those, coudn’t fix it, instead of: #"kikka.*" would have been enough to have [:re #"kikka.*] or even [:string {:format "kikka.*"}]

ikitommi13:05:32

I think in 90%+ cases people add anyway properties to the regexps like :error/message, so the benefit for supporting plain regexps is quite small.

Ben Sless13:05:16

An enhancement of regex error messages could be an indication at which character the match has failed. "Should match regex" isn't terribly helpful for humanized errors

nilern08:05:01

Host regexes don't support error positions. And I don't blame them, because the regex can fail in multiple ways at every character (our seqex schemas heuristically give the error the first longest partial match).

Ben Sless14:05:12

If we can do regex based generators we should theoretically be able to do regex based error reporting No one said it would be easy, or even a good idea. You may not want to expose your regex via error messages

mike_ananev13:05:18

[:= "v1.0.0"]đź‘Ť

Joel16:05:17

Is there a function that would give ":and" instead of ":or"? stricter vs. looser. maybe mu/intersect?

(mu/union [:map [:Event keyword?]] [:map [:Event [:enum :A :B]]])
=> [:map [Event [:or keyword? [:enum :A :B]...

ikitommi04:05:37

you can configure the the mu/merge with few options, see`:merge-default` in mu/union https://github.com/metosin/malli/blob/master/src/malli/util.cljc#L104-L113

ikitommi04:05:25

Would that be mu/intercect with :and ? If so, PR welcome.

ikitommi10:05:07

(my set theory skills are rusted on fridays)

nilern08:05:09

Intersection would go with :and (which is a lattice meet)

Ivan Fedorov18:05:40

any way to get schema name from RefSchema? e.g. I have [:schema {:registry reg} ::task] and it’s already a RefSchema

Ben Sless19:05:20

(m/deref schema)?

Ben Sless19:05:38

(let [schema (schema ?schema options)]
     (cond-> schema (satisfies? RefSchema schema) (-deref)))

Ben Sless19:05:12

Looks like just what you need

Ivan Fedorov19:05:09

@UK0810AQ2 thanks for the input! This gives something that looks like a keyword but in fact is a :malli.core/schema and I don’t understand how to get the keyword out

Ben Sless19:05:25

ah, hold on, let's dig some more

Ben Sless19:05:34

What's wrong with just calling m/form?

Ben Sless19:05:59

Okay, this is right:

(m/form (m/deref S))
You'll get back a keyword

🙏 2
Ivan Fedorov19:05:00

what you see in m/children is still a schema! but (-> m/form last) cuts it, thanks!