I haven't found an explicit note in the docs about this, so let me know if it's unsettled behavior that I shouldn't rely on: If I define a transformer such as
(defn my-transformer
[& {:as opts}]
(mt/transformer
{:decoders
{:map (fn [x] ...)}}))
Should I wrap the fn logic in an (if (map? x) ... x), or will this transformer only ever bind to maps (is 'bind' the right word? apply?)
ps: If there's any other docs/blog-posts about writing transformers beyond the /docs+readme in the repo, I'd love to read them, its definitely one of my weaker malli-subjectsAhhh I see, ok so I'll definitely keep those guard clauses then, I appreciate it (and the -safe pointer); i'll take a browse through that ns too ❤️
It will bind to :map schemas but the value could be anything.
I think the convention for encoders and decoders is to attempt to coerce the value but return it unchanged if that fails and not throw.
There are some examples in the malli.transform ns.
There is a -safe helper function there as well.
(defn -safe [f] #(try (f %) (catch #?(:clj Exception, :cljs js/Error) _ %)))A quick note acknowledging the value of this library once again. In the world of AI coding, getting errors at their source has become much more valuable to keep the agent on track. Malli is my go-to for this. Thanks again, team Malli!🙏
Yet another illustration that you can’t predict all the ways in which an open source tool will be used in the real world. And uncovering those possibilities is part of the pleasure of doing it.
cc #ai-assisted-coding
glad you like it!