Fork me on GitHub
#malli
<
2024-03-28
>
ambrosebs07:03:55

@ikitommi could we move the :=> guard to properties (before 0.15.0) and consider more flexible argument syntax (later)? I think adding a guard as the final argument locks in the restriction that the args must be a :cat. These would be nice: [:=> ret], [:=> arg1 ret], [:=> arg1 arg2 arg3 ret] . But the guard would then be indistinguishable from the ret if it's part of the children. There's a pointer here that seems to suggest it should be in the properties too https://github.com/metosin/malli/issues/608 (this should be referenced in the changelog, but there's a typo at the top of 0.15.0 that references the same issue twice).

ikitommi14:03:40

This was another option originally, but thought that having a new :-> that doesn’t support guards but would treat the last arg as return, wrap others in :cat would be cleaner for this. e.g. the following pairs would mean the same:

[:-> :int :int]
[:=> [:cat :int] :int]

:->
[:=> :cat :any]

[:-> :int]
[:=> :cat :int]

[:-> :int [:* :int] :int]
[:=> [:cat :int [:* :int]] :int]

ikitommi14:03:54

happy to hear your opinions on this.

1
ikitommi14:03:09

that kind of extra schema would not be many lines of code.

ambrosebs15:03:29

:-> sounds perfect.

ambrosebs15:03:18

Could add support for a guard in properties too for feature parity.

ambrosebs15:03:08

(I'm guessing :-> would just be sugar for :=> that just has a cleaner m/form )

ambrosebs15:03:18

It might be a good opportunity to consider non-cat args like [:=> [:* :int] :int] or [:=> [:alt :cat [:cat :foo :bar]] :any].

ambrosebs15:03:47

Is there much code depending on :=> input being :cat?

ambrosebs15:03:10

OTOH it's a pretty simple rule to remember that :-> always expands to a :cat no matter what.

ambrosebs15:03:40

(which was the motivation I had, say if you give :-> 1 arg which is a regex, you don't need to :cat )

ambrosebs16:03:19

here's a prototype :-> that supports a :fn property and always wraps args in :cathttps://github.com/metosin/malli/pull/1027/files

ambrosebs16:03:16

I think perhaps allowing non-cat args in :=> can be done separately (if ever) and we keep :-> consistently wrapping :cat.

ambrosebs16:03:05

I'm not a big fan of :-> without children. It starts to look like in an infix op. [:-> :a :-> :b]

pez20:03:08

I’m holding malli wrong again. The schema [:merge :map :map] works https://malli.io/?value=%7B%3Aa%2042%7D&amp;schema=%5B%3Amerge%20%3Amap%20%3Amap%5D, but not in my repl.

(comment
  (require '[malli.core :as m])
  (m/validate [:merge :map :map] {:name "World"})
  ;=> #error {:message ":malli.core/invalid- … ema {:schema :merge}" , :data {:type :malli.core/invalid-schema, :data {:schema :merge}}} {:type :repl/invoke, :name "<eval>", :js "malli.core.validate. … 77),"World"], null))" , :source "(m/validate [:merge … ap] {:name "World"})" , :source-map-json "{"version":3,↵ "file … name \"World\"})"]}↵" , …} 
  :rcf)
Ah, I see it now, I need to merge the malli.util schemas. I guess it could be made clearer on the playground which schemas are merged?

ikitommi08:03:50

Indeed it would be, also, it's using really old version of malli. And the code is copy&paste from Borkdudes really old sci-playground. All improvements most welcome!