routine reverse
1 | class List |
1.1 | (List) routine reverse |
2 | class Supply |
2.1 | (Supply) method reverse |
3 | class Range |
3.1 | (Range) method reverse |
4 | class Any |
4.1 | (Any) routine reverse |
5 | class Mix |
5.1 | (Mix) method reverse |
6 | role Blob |
6.1 | (Blob) method reverse |
Documentation for routine reverse
assembled from the following types:
class List
From List
(List) routine reverse
Defined as:
multi sub reverse(* --> Seq)multi method reverse(List: --> Seq)
Returns a Seq
with the same elements in reverse order.
Note that reverse
always refers to reversing elements of a list; to reverse the characters in a string, use flip.
Examples:
say <hello world!>.reverse; # OUTPUT: «(world! hello)»say reverse ^10; # OUTPUT: «(9 8 7 6 5 4 3 2 1 0)»
class Supply
From Supply
(Supply) method reverse
method reverse(Supply: --> Supply)
Taps the Supply
it is called on. Once that Supply
emits done
, all of the values it emitted will be emitted on the returned Supply
in reverse order. If the original Supply
quit
s, then the exception is immediately conveyed on the return Supply
.
my = Supply.from-list(1, 2, 3);my = .reverse;.tap(); # OUTPUT: «321»
class Range
From Range
(Range) method reverse
method reverse(Range: --> Seq)
Returns a Seq where all elements that the Range
represents have been reversed. Note that reversing an infinite Range
won't produce any meaningful results.
say (1^..5).reverse; # OUTPUT: «(5 4 3 2)»say ('a'..'d').reverse; # OUTPUT: «(d c b a)»say (1..∞).reverse; # OUTPUT: «(Inf Inf Inf ...)»
class Any
From Any
(Any) routine reverse
Defined as:
multi sub reverse(* --> Seq)multi method reverse(List: --> Seq)
Returns a Seq with the same elements in reverse order.
Note that reverse
always refers to reversing elements of a list; to reverse the characters in a string, use flip.
Examples:
say <hello world!>.reverse; # OUTPUT: «(world! hello)»say reverse ^10; # OUTPUT: «(9 8 7 6 5 4 3 2 1 0)»
class Mix
From Mix
(Mix) method reverse
Note: This method is inherited from Any, however, Mix
es do not have an inherent order and you should not trust it returning a consistent output.
role Blob
From Blob
(Blob) method reverse
Defined as:
method reverse(Blob: --> Blob)
Returns a Blob with all elements in reversed order.
say Blob.new([1, 2, 3]).reverse; # OUTPUT: «Blob:0x<03 02 01>»say blob16.new([2]).reverse; # OUTPUT: «Blob[uint16]:0x<02>»say buf32.new([16, 32]).reverse; # OUTPUT: «Buf[uint32]:0x<20 10>»