Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

handerpeder
Copy link
Contributor

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)

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 ikitommi merged commit fee1f17 into metosin:master Aug 10, 2023
@ikitommi
Copy link
Member

Thanks!

@ikitommi ikitommi mentioned this pull request Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants