method head
1 | class List |
1.1 | (List) method head |
2 | class Supply |
2.1 | (Supply) method head |
3 | class Any |
3.1 | (Any) method head |
Documentation for method head
assembled from the following types:
class List
From List
(List) method head
Defined as:
multi method head(Any:) is rawmulti method head(Any: Callable )multi method head(Any: )
This method is directly inherited from Any, and it returns the first $n
items of the list, an empty list if $n
<= 0, or the first element with no argument. The version that takes a Callable
uses a WhateverCode
to specify all elements, starting from the first, but the last ones.
Examples:
say <a b c d e>.head ; # OUTPUT: «a»say <a b c d e>.head(2); # OUTPUT: «(a b)»say <a b c d e>.head(*-3); # OUTPUT: «(a b)»
class Supply
From Supply
(Supply) method head
method head(Supply: Int(Cool) = 1 --> Supply)
Creates a "head" supply with the same semantics as List.head.
my = Supply.from-list(4, 10, 3, 2);my = .head(2);.tap(); # OUTPUT: «410»
class Any
From Any
(Any) method head
Defined as:
multi method head(Any:) is rawmulti method head(Any: Callable )multi method head(Any: )
Returns either the first element in the object, or the first $n
if that's used.
"aaabbc".comb.Mix.head.put; # OUTPUT: «c␉1»"aaabbc".comb.Mix.head.put; # OUTPUT: «a␉3»say ^10 .head(5); # OUTPUT: «(0 1 2 3 4)»say ^∞ .head(5); # OUTPUT: «(0 1 2 3 4)»say ^10 .head; # OUTPUT: «0»say ^∞ .head; # OUTPUT: «0»
In the first two cases, the results are different since there's no defined order in Mix
es. In the other cases, it returns a Seq
. A Callable
can be used to return all but the last elements:
say (^10).head( * - 3 );# OUTPUT: «(0 1 2 3 4 5 6)»