@@ -232,30 +232,35 @@ value, but unlike the above options, it will break L<Scalars|/type/Scalar>.
232
232
X < |laziness in iterable objects >
233
233
= head1 Lazy lists
234
234
235
- Lists, arrays, sequences and any class with the L < Iterator > role can be lazy,
236
- which means that their values are computed on demand and stored for later use.
237
- To create a lazy object use L < gather/take|/language/control#gather/take > or the
238
- L < sequence operator|/language/operators#infix_... > . You can also write a class
239
- that implements the role L < Iterator|/type/Iterator > and returns C < True > on a
240
- call to L < is-lazy|/routine/is-lazy > . Please note that some methods like C < elems >
241
- cannot be called on a lazy List and will result in a thrown
235
+ C < List > s, C < Seq > s (and any class that subclasses them, like C < Array > s) and
236
+ any other class thet implements the L < Iterable > role can be lazy, which means that their
237
+ values are computed on demand and stored for later use. To create a lazy object
238
+ use L < gather/take|/language/control#gather/take > or the L < sequence
239
+ operator|/language/operators#infix_... > . You can also write a class that
240
+ implements the role L < Iterator|/type/Iterator > and returns C < True > on a call to
241
+ L < is-lazy|/routine/is-lazy > . Please note that some methods like C < elems > cannot
242
+ be called on a lazy List and will result in a thrown
242
243
L < Exception|/type/Exception > .
243
244
244
- # This list is lazy and elements will not be available
245
+ # This array is lazy and its elements will not be available
245
246
# until explicitly requested.
246
247
247
- my @l = lazy 1, 11, 121 ... 10**100;
248
- say @l .is-lazy; # OUTPUT: «True»
249
- say @l []; # OUTPUT: «[...]»
248
+ my @lazy-array = lazy 1, 11, 121 ... 10**100;
249
+ say @lazy-array .is-lazy; # OUTPUT: «True»
250
+ say @lazy-array []; # OUTPUT: «[...]»
250
251
251
252
# Once all elements have been retrieved, the List
252
253
# is no longer considered lazy.
253
254
254
- my @no-longer-lazy = eager @l ; # Forcing eager evaluation
255
+ my @no-longer-lazy = eager @lazy-array ; # Forcing eager evaluation
255
256
say @no-longer-lazy.is-lazy; # OUTPUT: «False»
256
257
say @no-longer-lazy[];
257
258
# OUTPUT: (sequence starting with «[1 11 121» ending with a 300 digit number)
258
259
260
+ In the example above, C < @lazy-array > is an C < Array > which, through construction,
261
+ is make C < lazy > . When using it with C < is-lazy > it is returning an iterator,
262
+ which, since it originates in a lazy list, is itself lazy.
263
+
259
264
A common use case for lazy C < List > s is the processing of infinite sequences of
260
265
numbers, whose values have not been computed yet and cannot be computed in their
261
266
entirety. Specific values in the List will only be computed when they are
0 commit comments