malli 2025-05-21

Hi guy! What is the way to default like this:

[:map
  [:expr {:default-fn (fn [] (jt/instant))} inst?]]

I'd consider adding my own default-instant-transformer that does something like that

oh, you can actually reuse default-value-transformer and give it the :default-fn property!

huh, it looks like there's also support for a :default/fn property...

not documented

I'll come up with an example for this, later today

Thanks @joel.kaasinen for the :default/fn This works:

(m/decode [:map [:expr [inst? {:default/fn (fn [] (jt/instant))}]]]
            {}
            mt/default-value-transformer)
But not this:
(m/decode [:map [:expr {:default/fn (fn [] (jt/instant))} inst?]]
            {}
            mt/default-value-transformer)

Too bad that the :default/fn property is not documented

I intend to add docs for it

interesting that the latter version doesn't work. that might be a bug in the implementation.

You rocks!

🔥 1