Fork me on GitHub

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

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


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:

  [:=> [:* 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 👍


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


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


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


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


alright! malli-instrument now supports multi-arity fn schemas 😄 🎉 I'll continue working on this and pushing bugfixes

👍 9