metosin / malli

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

add :default/fn prop for default-value-transformer #927

Closed handerpeder closed 11 months ago

handerpeder commented 11 months ago

use case: we want the default value to be current time.

previously you would have to do something like this:

(m/decode
 [:time/instant {:default :now}]
 nil
 (mt/default-value-transformer {:default-fn
                                (fn [_ x ] (case x
                                             :now (java.time.Instant/now)
                                             x))}))

this patch lets you declare this without the indirection:

(m/decode [:time/instant {:default/fn #(java.time.Instant/now)}]
          nil
          mt/default-value-transformer)
ikitommi commented 11 months ago

Thanks!