-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 lazy versions of Object#getter?/property? macros #7322
Conversation
A At least, it should memorize whether the value has been initialized (which can be nil). |
I'm not sure if I follow... Using nil-able types for any of the class Foo
getter?(installed : Bool) { true }
end
foo = Foo.new
p foo.@installed # => nil
p foo.installed? # => true
p foo.@installed # => true
foo.installed = nil
p foo.@installed # => nil
p foo.installed? # => true
p foo.@installed # => true |
That's exactly my issue: what's the difference between Unless there are actual use cases that I'm obviously missing? The whole patch looks like a very edge case to me. I'm not sure that |
Yes I was suggesting what @ysbaddaden says. Else, this |
To know if the nillable variables was lazily initialized with the block, a second boolean variable has to be used. My use case here is to detect the Init system of the machine. I don't want to repeat the operation, and it can return |
@ysbaddaden I think there's some misunderstanding about the use cases for |
A lazy initialized boolean getter method just makes no sense to me at all. I can't see any use case 😕 |
@ysbaddaden a boolean's just another return type, it could be computed from the network, or some other expensive operation which is best done on-demand. |
@ysbaddaden One example comes from shards (sic!): |
40d67d3
to
f5bdf69
Compare
Since #7313 is merged, what brings this implementation vs. regular getter and property, despite the |
@j8r As I said before: it brings feature parity (lazy block initialization). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Sija 👍
@asterite Would you care for a review (& merge if all's good)? |
Sure, I'll do it in max 3 days. |
This PR adds lazy initialized versions of
Object#getter?/property?
. They do exist forgetter/property
macros, so that would bring feature parity to both variants.Possibly closes #7321