Fork me on GitHub

more batteries for value type inferring (

(require '[malli.provider :as mp])
(require '[malli.transform :as mt])

 [{:id "caa71a26-5fe1-11ec-bf63-0242ac130002"}
  {:id "8aadbf5e-5fe3-11ec-bf63-0242ac130002"}])
; => [:map [:id string?]]

 [{:id "caa71a26-5fe1-11ec-bf63-0242ac130002"}
  {:id "8aadbf5e-5fe3-11ec-bf63-0242ac130002"}]
 {::mp/value-providers {'string? {:uuid mt/-string->uuid}}})
; => [:map [:id :uuid]]

 [{"0423191a-5fee-11ec-bf63-0242ac130002" {:id "0423191a-5fee-11ec-bf63-0242ac130002"}
   "09e59de6-5fee-11ec-bf63-0242ac130002" {:id "09e59de6-5fee-11ec-bf63-0242ac130002"}
   "15511020-5fee-11ec-bf63-0242ac130002" {:id "15511020-5fee-11ec-bf63-0242ac130002"}}]
 {::mp/value-providers {'string? {:uuid mt/-string->uuid}}})
; => [:map-of :uuid [:map [:id :uuid]]]


I am encountering an arity error when I try to create a function schema for a multi-arity fn that accepts a vector of a specific type as an input.

  [:=> [:cat [:schema [:* :int]]] :any]
  [:=> [:cat [:schema [:* :int]] :boolean] :any]])
This produces the following error (I confirmed this with the latest tagged release of malli, 0.7.4):
{:type :malli.core/duplicate-arities,
    :message :malli.core/duplicate-arities,
     [{:min 0, :arity :varargs, :input [:cat [:schema [:* :int]]], :output :any}
      {:min 1,
       :arity :varargs,
       :input [:cat [:schema [:* :int]] :boolean],
       :output :any}]}}
I had figured that wrapping the input sequence schema in :schema would mark it as a distinct sequential value rather than a subcomponent of the input arg vector, but it appears that malli is treating an input vector of an arbitrary size as indicating that the function is supposed to have varargs, resulting in a clash between the arities of the function.


running mg/generate on the arity input seqexes independently produces values that I expect to see:

(mg/generate [:cat [:schema [:cat [:* :int]]] :boolean])
;; => ((-2 2096836 3803 45 -49393) false)
(mg/generate [:cat [:schema [:cat [:* :int]]]])
;; => ((-1709 -2289 -38 3962880 -8 -948 13075997 77734 -16118422 635358 2 -1 -1))


Looks like :schema has a bug related to m/-regex-min-max :

  [:cat [:schema [:* :int]]]))
; => {:min 0}
could you write an issue out of this?


while waiting, you can try:

  [:cat [:sequential :int]]))
; => {:min 1, :max 1}


.. and if it’s a vector, this is a way to describe it:

  [:=> [:cat [:vector :int]] :any]
  [:=> [:cat [:vector :int] :boolean] :any]])


but, please issue the original, as it’s a bug.