Fork me on GitHub
#malli
<
2021-12-18
>
ikitommi10:12:32

more batteries for value type inferring (https://github.com/metosin/malli/pull/597):

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

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

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

(mp/provide
 [{"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]]]

respatialized21:12:23

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.

(m/schema
 [:function
  [:=> [: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,
    :data
    {:infos
     [{: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.

respatialized22:12:12

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))

ikitommi08:12:32

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

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

ikitommi08:12:23

while waiting, you can try:

(m/-regex-min-max
 (m/schema
  [:cat [:sequential :int]]))
; => {:min 1, :max 1}

ikitommi08:12:28

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

(m/schema
 [:function
  [:=> [:cat [:vector :int]] :any]
  [:=> [:cat [:vector :int] :boolean] :any]])
ping @UFTRLDZEW

ikitommi08:12:45

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