Skip to content

Commit 5049338

Browse files
committed
clarify that :delete can create holes that are bit skipped by iteration
1 parent 501dd46 commit 5049338

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/Language/subscripts.pod

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ mechanism.
430430
431431
=head2 X<:delete|subscript adverb,:delete>
432432
433-
Delete the element from the collection, in addition to returning its value.
433+
Delete the element from the collection or, if supported by the collection,
434+
creates a hole at the given index, in addition to returning its value.
434435
435436
my @tens = 0, 10, 20, 30;
436437
dd @tens[3]:delete; #-> 30
@@ -441,6 +442,16 @@ Delete the element from the collection, in addition to returning its value.
441442
dd %fruit<peach orange>:delete; #-> (17, 10)
442443
dd %fruit; #-> {banana => 4}<>
443444
445+
The created holes can be tested for with C<:exists> but iteration will not skip
446+
them and produce undefined values instead.
447+
448+
my @a = 1,2,3;
449+
@a[1]:delete;
450+
say @a[1]:exists;
451+
# OUTPUT«False␤»
452+
.say for @a;
453+
# OUTPUT«1␤(Any)␤3␤»
454+
444455
With the negated form of the adverb, the element is not actually deleted. This
445456
means you can pass a flag to make it conditional:
446457

0 commit comments

Comments
 (0)