In Array§
See primary documentation in context for method shift
method shift(Array:) is nodal
Removes and returns the first item from the array. Fails if the array is empty.
Example:
my = <a b>;say .shift; # OUTPUT: «a»say .shift; # OUTPUT: «b»say .shift;CATCH ;# OUTPUT: «X::Cannot::Empty: Cannot shift from an empty Array»
In Independent routines§
See primary documentation in context for sub shift
multi shift() is 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 of Int = [1];say shift ; # OUTPUT: «1»say shift ; # ERROR: «Cannot shift from an empty Array[Int]»
In role Buf§
See primary documentation in context for method shift
method shift()
Removes and returns the first element of the buffer.
my = Buf.new( 1, 1, 2, 3, 5 );say .shift(); # OUTPUT: «1»say .raku; # OUTPUT: «Buf.new(1,2,3,5)»