malli

https://github.com/metosin/malli :malli:
Setzer22 2021-05-18T09:58:31.001500Z

The syntax to define multi-arity fns is this one, right?

[:function
  [:=> [:cat int? int?] int?]
  [:=> [:cat int?] string?]]

Setzer22 2021-05-18T10:24:01.012300Z

Ok, so I was asking because I'm implementing multi-arity schema support in my malli-instrument library, but I'm unsure how to best deal with instrumenting multi-arity fns with varargs. Due to the way in which varargs are specified, I don't have a way to know which of the arities under :function corresponds to each of the possible lengths of the arg list, or at least not without some analysis, consider the following:

[:function 
  [:=> [:* int?] int?]
  [:=> [:* string?] string?]]
this is a valid schema for:
(defn foo
  ([x y z] (+ x y z))
  ([a b c d & _] (str a b c d)))
it can be argued that it's an innacurate schema for the function, but that's not my point: Regardless of the example, the fact remains that with seqex patterns being used to define arglists, one can't easily determine which one of the annotated arities to take given an arglist and its length :thinking_face: The only way to do this with the current specification is to test each of the arity specs against the arglist until some validates. This is what I'm implementing now, but I thought it'd be good to bring out this discussion nontheless, in case you think the specification format could be improved 👍

Setzer22 2021-05-18T11:10:31.014600Z

nice, thanks! 👍 I was re-inventing the wheel for some of this work in a more inefficient way so this helps a lot

Setzer22 2021-05-18T11:12:22.014900Z

I'm confused, what's this second one doing? 😅

Setzer22 2021-05-18T13:49:49.016300Z

just noticed a small inconsistency when writing the instrumentation code: (m/validate :cat nil) returns false, but when calling (fn [& args]) with zero arguments, args is bound to nil

Setzer22 2021-05-18T13:51:22.018Z

I can easily work around it on my side using something like (or args '()), but I thought that may be something worth looking into

Setzer22 2021-05-18T13:54:52.018900Z

alright! malli-instrument now supports multi-arity fn schemas 😄 🎉 https://github.com/setzer22/malli-instrument I'll continue working on this and pushing bugfixes

👍 3