Documentation for method head

Documentation for method head, assembled from the following types:

class List

From List

(List) method head

Defined as:

method head(List:D: Int(Cool$number = 1 --> Seq:D)

Returns the first NUMBER items of the list. Returns an empty list if NUMBER <= 0. Defaults to the first element seen if no NUMBER specified.

Examples:

say ^10 .head(5);      # OUTPUT: «(0 1 2 3 4)␤» 
say ^Inf .head(5);     # OUTPUT: «(0 1 2 3 4)␤» 
say ^10 .head;         # OUTPUT: «0␤» 
say ^Inf .head;        # OUTPUT: «0␤» 

class Supply

From Supply

(Supply) method head

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

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

my $s = Supply.from-list(41032);
my $hs = $s.head(2);
$hs.tap(&say);           # OUTPUT: «4␤10␤»