metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.46k stars 208 forks source link

`mx/defn` improvement: always-check inputs and outputs #823

Closed escherize closed 1 year ago

escherize commented 1 year ago

It's often surprising to users when mx/defn behaves differently than (prismatic) schema.core/defn. Probably because they have very similar syntax.

It'd be cool if mx/defn provided a way to always check inputs and outputs like this defn macro does.

(mx/defn ^:always-check g :- :int [x :- :keyword] 3)

(g "non-keyword")
;; ==throws==> clojure.lang.ExceptionInfo
;; Message: 
;; "[[\"should be a keyword\"]]"
;; Data: 
;; {:type :malli.core/invalid-input,
;;  :data
;;  {:input [:cat :keyword], :args ["non-keyword"], :schema [:=> [:cat :keyword] :int], :fn-name malli.experimental/g},
;;  :humanized [["should be a keyword"]]}

Open Questions

Q: Is there another piece of information that would be good to include here? Q: Is it worth differentiating between ^:always-check-inputs and ^:always-check-outputs?

ikitommi commented 1 year ago

More points:

opqdonut commented 1 year ago

I think I have a minimum viable implementation over in #825 now.