You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gather/take can generate values lazily, depending on context. If you want to force lazy evaluation use the lazy subroutine or method. Binding to a scalar or sigilless container will also force laziness.
(let's ignore questionable “force laziness” stuff for now)
In some way it is right, but to me this is not enough. Surely it can generate values lazily, but how? What does it mean exactly? What should I write in order to get lazy behavior?
If I get it right (please correct me if I'm wrong), then if you have code like this:
say‘before’;
take42;
say‘after’;
…
Then say ‘after’ will not be executed unless you pull another value from the Seq. So your code just magically stops executing before returning from take. This means that you can write any kind of code, like infinite recursion and the like, and it won't run more than you ask it to. That's freaking awesome.
The text was updated successfully, but these errors were encountered:
not only that what i like about that feature you can have normal loop but in it you not take every iteration a value or sometimes two and so press irregular ebehaviour into seemingly regular frame
Because no mater what you are doing, you are still looping twice, and the data you have in .grep() may no longer be available in .map. Why do in two loops what can be done in one?
I'll look through some of my code and see if I can give a more concrete example.
Inspired by #2135 which says:
This is another case when an amazing feature is not explained enough.
Docs: https://docs.perl6.org/syntax/gather%20take
It says:
(let's ignore questionable “force laziness” stuff for now)
In some way it is right, but to me this is not enough. Surely it can generate values lazily, but how? What does it mean exactly? What should I write in order to get lazy behavior?
See my mumblings here: http://colabti.org/irclogger/irclogger_log/perl6?date=2018-10-17#l34
If I get it right (please correct me if I'm wrong), then if you have code like this:
Then
say ‘after’will not be executed unless you pull another value from the Seq. So your code just magically stops executing before returning fromtake. This means that you can write any kind of code, like infinite recursion and the like, and it won't run more than you ask it to. That's freaking awesome.The text was updated successfully, but these errors were encountered: