What's the recommended location for function schema definition? Should it be on the same namespace as the function or in a separate namespace?
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
what do you think?
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
I tend to prefer to have the schemas near the code as schemas serve also as documentation
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 ๐
One option would be this
make an aspect for it
^{::m/aspects [(contract [:=> [:cat int? int?] string?])]}
(m/defn some-fn [x y]
(str (+ x y))
Does malli support plumatic style? how?
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.
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
and, to be compliant: 4. the spec registry
Ok
@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
this works too:
(m/=> plus [:=> [:cat [:* :int]] :int])
(defn plus [& ns] (apply + ns))
(plus 1 2 3)
; => 6
Nice. In fact malli treats function names as symbols
So it doesn't matter if you create the schema before the function is defined