routine splice

Documentation for routine splice assembled from the following types:

class Array

From Array

(Array) routine splice

Defined as:

multi sub    splice(@list,   $start = 0$elems?*@replacement --> Array)
multi method splice(Array:D: $start = 0$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. If both $start and $elems are omitted, all elements are deleted from the Array and returned.

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 $elems 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]␤» 

role Buf

From Buf

(Buf) method splice

method spliceBuf:D: $start = 0$elems?*@replacement --> Buf)

Substitutes elements of the buffer by other elements

    $.splice:  03, <3 2 1>;
    say $.perl# OUTPUT: «Buf.new(3,2,1,2,3,5,8,13,21,34,55,89)»