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

Schema: add effectful constructors to Struct and Class to allow effectful defaults #3930

Open
adrian-gierakowski opened this issue Nov 12, 2024 · 0 comments
Labels
enhancement New feature or request schema

Comments

@adrian-gierakowski
Copy link
Contributor

adrian-gierakowski commented Nov 12, 2024

What is the problem this feature would solve?

I'd like to be able to add defaults for properties of type Date\DateTime, which would default to current time if not set.

Currently the default cannot be created via the Clock service (like with DateTime.now) since defaults cannot be effectful.

What is the feature you are proposing to solve the problem?

Add static makeEffect (effectful counterpart of make) to Struct and Class and and allow effects to be used in constructor defaults and in optionalWith

What alternatives have you considered?

currently it's possible to achieve effectul defaults when encoding and decoding by creating a custom transform. This has a couple of drawbacks:

  1. one needs to actually encode\decode to generate the default
  2. the property cannot be made required on both sides of the transform (for encoding defaults, decoded prop needs to be optional, and vice versa)

implementation of effectful encode\decode defaults can be found here (decode) and here (encode)

related issue: #3919
related discrod thread: https://discord.com/channels/795981131316985866/1304719283263246400

@adrian-gierakowski adrian-gierakowski added the enhancement New feature or request label Nov 12, 2024
@gcanti gcanti added the schema label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request schema
Projects
None yet
Development

No branches or pull requests

2 participants