Skip to content

Commit

Permalink
Adds head, refs #1494 #2631
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Feb 21, 2019
1 parent ee348ea commit a1bc2eb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/Type/Any.pod6
Expand Up @@ -1129,6 +1129,29 @@ say <0 1 2>.toggle: :off, * > 1; # OUTPUT: «(2)␤»
# 2 => 2 > 1 === True switch is on, "2" makes it into the result
=end code
=head2 method head
Defined as:
multi method head(Any:D:) is raw
multi method head(Any:D: Callable:D $w)
multi method head(Any:D: $n)
Returns either the first element in the object, or the first C<$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 C<Mix>es. In the other cases, it returns a C<Seq>. A C<Callable> can be used
to return all but the last elements:
say (^10).head( * - 3 );# OUTPUT: «(0 1 2 3 4 5 6)␤»
=head2 method tree
Expand Down

0 comments on commit a1bc2eb

Please sign in to comment.