Fork me on GitHub
#malli
<
2021-02-07
>
ikitommi08:02:49

Not sure how useful the function schema checking is in real life (maybe for tooling?), but here’s the wip:

(require '[malli.generator :as mg])

(def check
  (mg/function-checker
    [:function
     [1 [:=> [:cat :int] :int]]
     [2 [:=> [:cat :int :int] [:int {:max 10}]]]]))

(check
  (fn
    ([x] x)
    ([x y] (mod (+ x y) 10))))
; => nil

(check
  (fn
    ([x] x)
    ([x y] (+ x y))))
;({:total-nodes-visited 18,
;  :depth 6,
;  :pass? false,
;  :result false,
;  :result-data nil,
;  :time-shrinking-ms 0,
;  :smallest [(0 11)],
;  :malli.core/schema [:=> [:cat :int :int] [:int {:max 10}]]})

(check
  (fn
    ([x y] (mod (+ x y) 10))))
;({:total-nodes-visited 0,
;  :depth 0,
;  :pass? false,
;  :result "Wrong number of args (1) passed to: user/eval97462/fn--97463",
;  :time-shrinking-ms 0,
;  :smallest [(0)],
;  :malli.core/schema [:=> [:cat :int] :int]})

ikitommi07:02:25

this @UG9U7TPDZ, in master, will be released soon.

caumond09:02:33

hi, I search a little bit long before finding that representing date in malli could be easily done with inst? Is it a recommended approach? I have a doubt as I would expect to find a reference of that in the malli doc which I did not.

caumond17:02:30

Yes, I saw the PR, it was not completely enlightening. I understood something is missing, some of the proposal, but I did not understand there what is the recommend approach awaiting for that PR to be merged.

caumond17:02:53

I keep the "`inst` is ok" part !

ikitommi11:02:00

:not merged in master:

(mg/sample [:not :string])
;([]
; #{}
; nil
; \$
; nil
; nil
; {#uuid"3565d7f3-5561-439f-9368-5bfdbd03fc8e" -2/3}
; ()
; [\^]
; [[-110317951337N \:] #{2.15625 R+3/qfp}])