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

Suppliers.memoize should return a MemoizingSupplier with isMemoized() #7292

Open
3 tasks done
alexey-pelykh opened this issue Jul 7, 2024 · 4 comments
Open
3 tasks done
Labels

Comments

@alexey-pelykh
Copy link

API(s)

`com.google.common.base.Suppliers::memoize`

How do you want it to be improved?

Get memoizing supplier state without causing memoization

Why do we need it to be improved?

To check the memoizing supplier state without changing it

Example

N/A as there's no such feature

Current Behavior

MemoizingSupplier::initialized is not exposed

Desired Behavior

MemoizingSupplier::initialized is exposed

Concrete Use Cases

e.g. in toString() of a class that needs to print a memoized supplier value without causing the memoization

Checklist

@cgdecker
Copy link
Member

cgdecker commented Jul 11, 2024

e.g. in toString() of a class that needs to print a memoized supplier value without causing the memoization

Does the default toString() of the memoizing supplier not work for you? It doesn't trigger the memoization if it hasn't occurred yet.

My inclination is that this is niche enough that I'd suggest just writing your own, perhaps even wrapping a single-element LoadingCache or something.

@alexey-pelykh
Copy link
Author

While toString() use-case could be mitigated, I fail to see how exposing a property that's already there can be harmful. Currently I have to resort to using Apache Commons because there's LazyInitializer.html#isInitialized - however I find it's usage bulky in comparison to MemoizingSupplier.

@xc-x
Copy link

xc-x commented Oct 17, 2024

Hi, I want to solve this issue. Could you please assign to me?

@alexey-pelykh
Copy link
Author

@xc-x I already have a draft implementation that I wanted to share if/when the suggestion would be agreed upon, yet here it is #7450

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

No branches or pull requests

3 participants