Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hopefully clarify Array.push/append/unshift/prepend differences better
  • Loading branch information
lizmat committed Sep 16, 2018
1 parent a463da2 commit 93ebaac
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions doc/Type/Array.pod6
Expand Up @@ -44,7 +44,7 @@ Defined as:
multi sub push(Array:D, **@values --> Array:D)
multi method push(Array:D: **@values --> Array:D)
Adds the C<@values> to the end of the array, and returns the modified list.
Adds the C<@values> to the end of the array, and returns the modified array.
Throws for lazy arrays.
Example:
Expand Down Expand Up @@ -85,11 +85,12 @@ sub append(\array, elems)
multi method append(Array:D: **@values is raw)
Appends the argument list to the array passed as the first argument. This
modifies the array in-place. Returns the modified array. Throws for lazy arrays.
modifies the array in-place. Returns the modified array. Throws for lazy
arrays.
The difference from method C<push> is that with an array or list argument,
C<append> appends several elements (one for each array or list element),
whereas C<push> appends just one element.
The difference from method C<push> is that if you append a B<single> array
or list argument, C<append> will flatten that array / list, whereas C<push>
appends the list / array as just a single element.
Example:
Expand Down Expand Up @@ -168,7 +169,7 @@ Defined as:
multi method unshift(Array:D: **@values --> Array:D)
Adds the C<@values> to the start of the array, and returns the modified array.
Fails if C<@values> is infinite.
Fails if C<@values> is a lazy list.
Example:
Expand Down Expand Up @@ -201,6 +202,10 @@ Example:
@foo.prepend: 1, 3 ... 11;
say @foo; # OUTPUT: «[1 3 5 7 9 11 a b c]␤»
The difference from method C<unshift> is that if you prepend a B<single> array
or list argument, C<prepend> will flatten that array / list, whereas C<unshift>
prepends the list / array as just a single element.
=head2 routine splice
Defined as:
Expand Down

0 comments on commit 93ebaac

Please sign in to comment.