Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[List] sort, rotate
  • Loading branch information
moritz committed Jun 10, 2012
1 parent 7233ae8 commit afb84de
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/List.pod
Expand Up @@ -189,4 +189,33 @@ stop at the point where the infinity is detected.
Returns a list with the elements in reverse order.
=head3 rotate
multi sub rotate(@list, Int:D $n = 1) returns List:D
multi method rotate(List:D: Int:D $n = 1) returns List:D
Returns the list rotated by C<$n> elements.
<a b c d e>.rotate(2); # <c d e a b>
<a b c d e>.rotate(-1); # <e a b c d>
=head3 sort
multi sub sort(*@elems) returns List:D
multi sub sort(&by, *@elems) returns List:D
multi method sort(List:D:) returns List:D
multi method sort(List:D:, &by) returns List:D
Sorts the list, smallest element first. By default C<< infix:<cmp> >>
is used for comparing list elements.
If C<&by> is provided, and it accepts two arguments,
it is invoked for pairs of list elements, and should return
C<Order::Increase>, C<Order::Same> or C<Order::Decrease>.
If C<&by> accepts only one argument, the list elements are sorted
according to C<< by($a) cmp by($b) >>. The return values of C<&by> are
cached, so that C<&by> is only called once per list element.
=end pod

0 comments on commit afb84de

Please sign in to comment.