Documentation for routine prepend
assembled from the following pages:
Class: Any §
From Any
(Any) method prepend §
Defined as:
multi method prepend(Any: --> Array)multi method prepend(Any: --> Array)
Called with no arguments on an empty variable, it initializes it as an empty Array; if called with arguments, it creates an array and then applies Array.prepend
on it.
my ;say .prepend; # OUTPUT: «[]» say ; # OUTPUT: «[]» my ;say .prepend(1,2,3); # OUTPUT: «[1 2 3]»
Class: Nil §
From Nil
(Nil) method prepend §
method prepend(*@)
Warns the user that they tried to prepend onto a Nil
or derived type object.
Role: Buf §
From Buf
(Buf) method prepend §
method prepend( )
Adds elements at the beginning of the buffer
.prepend( 0 );say .raku; # OUTPUT: «Buf.new(0,1,1,2,3,5,8,13,21,34,55,89)»
Class: Array §
From Array
(Array) routine prepend §
Defined as
sub prepend(\array, |elems)multi method prepend(Array: \values)multi method prepend(Array: ** is raw)
Adds the elements from LIST
to the front of the array, modifying it in-place.
Example:
my = <a b c>;.prepend: 1, 3 ... 11;say ; # OUTPUT: «[1 3 5 7 9 11 a b c]»
The difference from method unshift
is that if you prepend a single array or list argument, prepend
will flatten that array / list, whereas unshift
prepends the list / array as just a single element.