routine shift

Documentation for routine shift assembled from the following types:

language documentation Independent routines

From Independent routines

(Independent routines) sub shift

Defined as:

multi sub shift(@ais raw

Calls method shift on the Positional argument. That method, on a mutable collection that actually implements it (such as an Array or a Buf), is supposed to remove and return the first element, or return a Failure if the collection is empty.

Example:

say shift [1,2]; # OUTPUT: «1␤»
my @a of Int = [1];
say shift @a# OUTPUT: «1␤» 
say shift @a# ERROR: «Cannot shift from an empty Array[Int]␤» 

class Array

From Array

(Array) method shift

Defined as:

method shift(Array:D:is nodal

Removes and returns the first item from the array. Fails if the array is empty.

Example:

my @foo = <a b>;
say @foo.shift;             # OUTPUT: «a␤» 
say @foo.shift;             # OUTPUT: «b␤» 
say @foo.shift;
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::Cannot::Empty: Cannot shift from an empty Array␤»

role Buf

From Buf

(Buf) method shift

method shift()

Takes out the first element of the buffer

$.shift();
say $.raku# OUTPUT: «Buf.new(1,1,2,3,5,8,13,21,34,55,89)»