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

Lazy Value #272

Open
juliancoffee opened this issue Aug 20, 2022 · 2 comments
Open

Lazy Value #272

juliancoffee opened this issue Aug 20, 2022 · 2 comments

Comments

@juliancoffee
Copy link
Contributor

In some cases, one would want to evaluate value only if needed.

I was thinking about using FluentValue::Custom for that, but at the most naive approach using simple closure may not work, because it needs duplicate.
To workaround that we could either make our own closure type aka struct of Args and fn and in duplicate, we would duplicate Args and fn.
But alternatively, I think it depends on how 'duplicate' is used, because we may also consider just evaluating closure in duplicate and returning a resulting value.

@juliancoffee
Copy link
Contributor Author

In the process of implementing it via FluentValue::Custom and during implementing FluentType for LazyValue, I found that FluentValue doesn't implement FluentType. Shouldn't it? 🤔

@gregtatum
Copy link
Member

I added this documentation to FluentType:

/// Custom types can implement the [`FluentType`] trait in order to generate a string
/// value for use in the message generation process.

So it seems like Custom types are fine being the only implementers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants