Skip to content

Commit

Permalink
Rewrites tail closes #2631
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Feb 23, 2019
1 parent 0e2a128 commit 45a20b4
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions doc/Type/List.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,27 @@ Examples:
Defined as:
method tail(List:D: Int(Cool) $number = 1 --> Seq:D)
multi method tail(List:D:)
multi method tail(List:D: $n --> Seq:D)
Returns a L<Seq|/type/Seq> containing the B<last> NUMBER items of the list.
Returns an empty C<Seq> if NUMBER <= 0. Defaults to the last element if
no NUMBER is specified. Throws an exception if the list is lazy.
Returns a L<Seq|/type/Seq> containing the B<last> C<$n> items of the list.
Returns an empty C<Seq> if C<$n> <= 0. Defaults to the last element if
no argument is specified. Throws an exception if the list is lazy.
Examples:
=for code
say ^10 .tail(5); # OUTPUT: «(5 6 7 8 9)␤»
say ^∞ .tail(5); # Cannot tail a lazy list
say ^10 .tail; # OUTPUT: «(9)␤»
say ^∞ .tail; # Cannot tail a lazy list
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, C<$n> is taking the shape of a C<WhateverCode> to indicate
the number of elements from the beginning that will be excluded. C<$n> can be
either a Callable, in which case it will be called with the value C<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 C<Seq>.
say <a b c d e>.tail( { $_ - 2 } ); # OUTPUT: «(c d e)␤»
=head2 routine categorize
Expand Down

0 comments on commit 45a20b4

Please sign in to comment.