metosin / malli

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

Allow instrumenting external functions #841

Closed NoahTheDuke closed 1 year ago

NoahTheDuke commented 1 year ago

~Here's a currently broken attempt at fixing #840. I don't know enough about cljs to know how to solve it, but for clj it works well enough.~

I should note that in clj, it doesn't work for any function that is "inlined". So, if you say (m/=> clojure.core/inc [:=> [:cat :int] :int]), calling (inc "1") won't be instrumented as it's compiled to a raw Numbers.inc("1") call. However, writing (#'inc "1") will be instrumented as it will be compiled into const__0.invoke("i").

I think that if this is noted in the docs it's an acceptable trade-off.

Closes #840

ikitommi commented 1 year ago

Looks good and a change most welcome, thanks!