malli

https://github.com/metosin/malli :malli:
mike_ananev 2021-05-06T12:19:20.229900Z

what is the difference between :or and :alt ?

mike_ananev 2021-05-06T12:22:00.230500Z

found in docs, :alt is for spec inside seq

đź‘Ť 1
mike_ananev 2021-05-06T12:59:37.231600Z

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

mike_ananev 2021-05-06T13:00:05.232200Z

[:enum "v1.0.0"] ?

mike_ananev 2021-05-06T13:00:22.232500Z

is there other ways?

mike_ananev 2021-05-06T13:02:52.233700Z

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

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

ikitommi 2021-05-06T13:11:05.234400Z

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

ikitommi 2021-05-06T13:14:34.237200Z

#{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.

ikitommi 2021-05-06T13:15:09.237900Z

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

ikitommi 2021-05-06T13:16:56.239900Z

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.*"}]

ikitommi 2021-05-06T13:18:32.241300Z

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.

nilern 2021-05-10T08:49:01.272600Z

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 Sless 2021-05-10T14:59:12.273Z

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

Ben Sless 2021-05-06T13:25:16.241400Z

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

mike_ananev 2021-05-06T13:51:18.241700Z

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

Joel 2021-05-06T16:53:17.244900Z

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]...

ikitommi 2021-05-07T10:49:07.251100Z

(my set theory skills are rusted on fridays)

nilern 2021-05-10T08:52:09.272800Z

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

Ivan Fedorov 2021-05-06T18:50:40.245600Z

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

Ben Sless 2021-05-06T19:22:20.246Z

(m/deref schema)?

Ben Sless 2021-05-06T19:22:38.246200Z

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

Ben Sless 2021-05-06T19:23:12.246400Z

Looks like just what you need

Ivan Fedorov 2021-05-06T19:43:09.246600Z

@ben.sless 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 Sless 2021-05-06T19:46:25.247300Z

ah, hold on, let's dig some more

Ben Sless 2021-05-06T19:49:34.247600Z

What's wrong with just calling m/form?

Ben Sless 2021-05-06T19:53:59.248600Z

Okay, this is right:

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

🙏 1
Ivan Fedorov 2021-05-06T19:54:00.248800Z

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