method tail

Documentation for method tail assembled from the following types:

class List

From List

(List) method tail

Defined as:

multi method tail(List:D:)
multi method tail(List:D: $n --> Seq:D)

Returns a Seq containing the last $n items of the list. Returns an empty Seq if $n <= 0. Defaults to the last element if no argument is specified. Throws an exception if the list is lazy.

Examples:

say <a b c d e>.tail(*-3);# OUTPUT: «(d e)␤» 
say <a b c d e>.tail(2);  # OUTPUT: «(d e)␤» 
say <a b c d e>.tail;     # OUTPUT: «e␤» 

In the first case, $n is taking the shape of a WhateverCode to indicate the number of elements from the beginning that will be excluded. $n can be either a Callable, in which case it will be called with the value 0, or anything else that can be converted to a number, in which case it will use that as the number of elements in the output Seq.

say <a b c d e>.tail{ $_ - 2 } ); # OUTPUT: «(c d e)␤»

class Supply

From Supply

(Supply) method tail

method tail(Supply:D: Int(Cool$number = 1 --> Supply:D)

Creates a "tail" supply with the same semantics as List.tail.

my $s = Supply.from-list(41032);
my $ts = $s.tail(2);
$ts.tap(&say);           # OUTPUT: «3␤2␤»

class Any

From Any

(Any) method tail

Defined as:

multi method tail() is raw
multi method tail($n)

Returns the last or the list of the $n last elements of an object. $n can be a Callable, usually a WhateverCode, which will be used to get all but the first n elements of the object.

say (^12).reverse.tail ;     # OUTPUT: «0␤» 
say (^12).reverse.tail(3);   # OUTPUT: «(2 1 0)␤» 
say (^12).reverse.tail(*-7); # OUTPUT: «(4 3 2 1 0)␤»