malli

J 2025-05-21T09:57:32.114759Z

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

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

opqdonut 2025-05-21T10:23:21.826909Z

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

opqdonut 2025-05-21T10:23:54.197739Z

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

opqdonut 2025-05-21T10:24:43.573389Z

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

opqdonut 2025-05-21T10:25:02.653689Z

not documented

opqdonut 2025-05-21T10:25:20.026569Z

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

opqdonut 2025-05-21T10:25:59.642119Z

test case is here: https://github.com/metosin/malli/blob/master/test/malli/transform_test.cljc#L1072

J 2025-05-21T11:24:19.279819Z

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)

J 2025-05-21T11:24:36.274309Z

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

opqdonut 2025-05-21T11:26:43.720209Z

I intend to add docs for it

opqdonut 2025-05-21T11:27:10.932499Z

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

opqdonut 2025-05-21T11:48:11.318589Z

fix incoming: https://github.com/metosin/malli/pull/1209

🎉 1
J 2025-05-21T11:49:43.392299Z

You rocks!

🔥 1