malli

https://github.com/metosin/malli :malli:
ikitommi 2021-02-07T08:41:49.065900Z

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

caumond 2021-02-07T09:01:33.067300Z

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.

ikitommi 2021-02-07T11:20:56.067500Z

inst? is ok, but see https://github.com/metosin/malli/issues/49

ikitommi 2021-02-07T11:22:00.068200Z

: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}])

caumond 2021-02-07T17:12:30.068300Z

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.

caumond 2021-02-07T17:13:53.068500Z

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