malli

https://github.com/metosin/malli :malli:
Yehonathan Sharvit 2021-06-22T09:07:09.188200Z

ok. will do

Yehonathan Sharvit 2021-06-22T09:08:43.189200Z

What's the recommended location for function schema definition? Should it be on the same namespace as the function or in a separate namespace?

ikitommi 2021-06-22T14:27:48.192900Z

No strong opinions in malli for that. My favourites: 1. Inlined (the plumatic syntax) 2. just before the functions (`m/=>` is as long as defn , looks good

ikitommi 2021-06-22T14:27:55.193200Z

what do you think?

Yehonathan Sharvit 2021-06-22T14:45:38.194500Z

Someone reviewed my code that added m/=> for each and every function in the core namespace of a lib (around 10 functions) and he thought it was polluting the namespace

Yehonathan Sharvit 2021-06-22T14:46:54.195300Z

I tend to prefer to have the schemas near the code as schemas serve also as documentation

eskos 2021-06-22T15:13:14.196400Z

I prefer the Plumatic style as it's more about upfront (meta) data expression, m/=> feels unnecessarily clever and sort of indirect/IoC hellish since it comes after the function declaration. But that's just my two cents ๐Ÿ™‚

emccue 2021-06-22T15:14:50.196800Z

One option would be this

emccue 2021-06-22T15:14:51.197Z

https://github.com/galdre/morphe

1
emccue 2021-06-22T15:15:33.197500Z

make an aspect for it

emccue 2021-06-22T15:16:22.198600Z

^{::m/aspects [(contract [:=> [:cat int? int?] string?])]}
(m/defn some-fn [x y]
  (str (+ x y))

Yehonathan Sharvit 2021-06-22T15:22:16.199300Z

Does malli support plumatic style? how?

ikitommi 2021-06-22T16:26:42.199500Z

wip, https://github.com/metosin/malli/pull/305

1๐Ÿ‘1๐Ÿ˜
ikitommi 2021-06-23T17:51:16.203600Z

the plumatic syntax has been out since 2013 and I believe it's the most used syntax, by far. I have used it, it's just good.

ikitommi 2021-06-23T17:53:23.203800Z

I like also the`:malli/schema` suggestion, the malli.instrument could be configured to support multiple sources like: 1. the => registry 2. the :malli/schema metadata 3. plain old function schema inferrer

1โœ…
ikitommi 2021-06-23T17:54:05.204Z

and, to be compliant: 4. the spec registry

Yehonathan Sharvit 2021-06-22T16:29:25.199800Z

Ok

Yehonathan Sharvit 2021-06-22T16:31:10.200900Z

@ikitommi In your previous message, you wrote: > just before the functions (`m/=>`ย is as long asย `defn`ย , looks good What do you mean by m/=> before the function? In malli's README, m/=> comes after the function definition

ikitommi 2021-06-22T16:35:18.201300Z

this works too:

(m/=> plus [:=> [:cat [:* :int]] :int])
(defn plus [& ns] (apply + ns))

(plus 1 2 3)
; => 6

ikitommi 2021-06-22T16:36:38.201400Z

#(apply println %&) = println :awesome:

Yehonathan Sharvit 2021-06-22T16:37:59.202100Z

Nice. In fact malli treats function names as symbols

Yehonathan Sharvit 2021-06-22T16:38:19.202500Z

So it doesn't matter if you create the schema before the function is defined