malli icon indicating copy to clipboard operation
malli copied to clipboard

Idea: align predicate and base schemas

Open frenchy64 opened this issue 1 year ago • 2 comments

It might reduce confusion between e.g., int? and :int if we define one in terms of the other via -proxy-schema.

I realize the point of the the predicates is to look like spec predicates, but it's an easy mistake to make to think :any and any? are synonymous. A better example: for int? it's not obvious it doesn't support :min/max properties.

Another advantage of using proxies here is we can reduce the implementation burden on multimethods that dispatch on m/type. Instead of a defmethod for :any and any?, you could have a defmethod :any and in the default method recur via m/deref to catch the :any case.

It's convenient to proxy things like map? as [:map-of :any :any], I think all current children can stay the same.

This is just a sketch and I have no idea why the test fail.

frenchy64 avatar Aug 18 '24 23:08 frenchy64

I love this idea and fully support it. I had no idea there were differences and I don't think this is mentioned in the readme.

NoahTheDuke avatar Aug 18 '24 23:08 NoahTheDuke

Agree that there are real problems here:

  1. people use string? instead of :string
  2. lot's of extra dispatching (transformers, generators etc)

Original issue is here and I did a study on this while back, did not push it out as PR it seems 🤔. I'll pull it out and comment more. I thought that solution would remove a lot of clutter (extra mappings in error messages, transformers, generators etc), but was not happy with the end result.

Let's park this PR for now.

ikitommi avatar Aug 27 '24 13:08 ikitommi

I would like to sunset the predicate schemas from the default registry. Too many ways to do the same thing now. This could be part of Malli 1.0.0 as it would be a breaking change. There could be a predicate registry in a seprate namespace for people who want to use this.

ikitommi avatar Mar 26 '25 08:03 ikitommi

Sounds good!

frenchy64 avatar Mar 26 '25 18:03 frenchy64