File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -283,11 +283,20 @@ As hinted above, scalar containers prevent that flattening:
283
283
my @a = 1, 2, 3;
284
284
say f $@a, 4, 5; # OUTPUT: «3»
285
285
286
- The C < @ > character can also be used as a prefix to remove a scalar container:
286
+ The C < @ > character can also be used as a prefix to coerce the argument to a list, thus removing a scalar container:
287
287
288
288
my $x = (1, 2, 3);
289
289
.say for @$x; # 3 iterations
290
290
291
+ However, the C « <> » is more appropriate to decontainerize items that aren't
292
+ lists:
293
+
294
+ my $x = ^Inf .grep: *.is-prime;
295
+ say "$_ is prime" for @$x; # WRONG! List keeps values, thus leaking memory
296
+ say "$_ is prime" for $x<>; # RIGHT. Simply decont the Seq
297
+
298
+ my $y := ^Inf .grep: *.is-prime; # Even better; no Scalars involved at all
299
+
291
300
Methods generally don't care whether their invocant is in a scalar, so
292
301
293
302
my $x = (1, 2, 3);
You can’t perform that action at this time.
0 commit comments