Closed lichtkind closed 6 years ago
The AttrX::Lazy trait is pretty simple as it does not check if the attribute has been built, but instead if it is already defined, and store it's value in a private attribute. So one solution is to test the "defineness" of the underlying private attribute, like the following:
> use AttrX::Lazy;
Nil
> class TestLazy { has $.lazy is lazy; method !build_lazy() { return "calculated"; };method is_already_there() { if $!lazy.defined { say "it is" } else { say "it is not" } } }
(TestLazy)
> my TestLazy $a .= new;
TestLazy.new(lazy => Any)
> $a.is_already_there()
it is not
> say $a.lazy
calculated
> $a.is_already_there()
it is
it could be an easy addition to the trait, however, i'm short of a good interface for it, i could import a function has_{attribute} name as Moo does it in perl5, but the predicate is not only for attributes, let me know your thought
thank you very much that helps me a lot I hope you like the direction I take with your lib but after the eigenstuff i will it slow down for now
I did recently some optimizations and think about others. One can greatly enhance the computation if some properties of a matrix are know. but sometimes this properties are computed using the function the could get the optimization. So I ask is there a way to ask a lazy attribute if is already evaled.
Thanks Pierre