Documentation for sub splice

Documentation for sub splice, assembled from the following types:

class Array

From Array

(Array) routine splice

Defined as:

multi sub    splice(@list,  $start$elems?*@replacement --> Array)
multi method splice(Array:D $start$elems?*@replacement --> Array)

Deletes $elems elements starting from index $start from the Array, returns them and replaces them by @replacement. If $elems is omitted, all the elements starting from index $start are deleted.

Each of $start and $elems can be specified as a Whatever or as a Callable that returns an int-compatible value.

A Whatever $start uses the number of elements of @list (or invocant). A Callable $start is called with one argument—the number of elements in @list—and its return value is used as $start.

A Whatever $elems deletes from $start to end of @list (same as no $elems). A Callable $elements is called with just one argument—the number of elements in @list minus the value of $start—and its return value is used the value of $elems.

Example:

my @foo = <a b c d e f g>;
say @foo.splice(23, <M N O P>);        # OUTPUT: «[c d e]␤» 
say @foo;                                # OUTPUT: «[a b M N O P f g]␤»