Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
document Range infixs #2739
  • Loading branch information
antoniogamiz committed May 12, 2019
1 parent af2115c commit 0899a01
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion doc/Type/Range.pod6
Expand Up @@ -335,7 +335,7 @@ element can not be coerced into Numeric.
method reverse(Range:D: --> Seq:D)
Returns a L<Seq|/type/Seq> where all elements that the C<Range> represents have
been reversed. Note that reversing an infinite C<Range> won't produce any
been reversed. Note that reversing an infinite C<> won't produce any
meaningful results.
say (1^..5).reverse; # OUTPUT: «(5 4 3 2)␤»
Expand Down Expand Up @@ -379,6 +379,66 @@ C<self.elems>. Returns C<False> otherwise.
say (6..10).EXISTS-POS(2); # OUTPUT: «True␤»
say (6..10).EXISTS-POS(7); # OUTPUT: «False␤»
=head2 sub infix:<+>
multi sub infix:<+>(Range:D \r, Real:D \v)
multi sub infix:<+>(Real:D \v, Range:D \r)
Takes an L<C<Real>|/type/Real> and adds that number to both
boundaries of the L<Range|/type/Range> object. Be careful with
the use of parenthesis.
say (1..2) + 2; # OUTPUT: «3..4␤»
say 1..2 + 2; # OUTPUT: «1..4␤»
=head2 sub infix:<->
multi sub infix:<->(Range:D \r, Real:D \v)
Takes an L<C<Real>|/type/Real> and substract that number to both
boundaries of the L<Range|/type/Range> object. Be careful with
the use of parenthesis.
say (1..2) - 1; # OUTPUT: «0..1␤»
say 1..2 - 1; # OUTPUT: «1..1␤»
=head2 sub infix:<*>
multi sub infix:<*>(Range:D \r, Real:D \v)
multi sub infix:<*>(Real:D \v, Range:D \r)
Takes an L<C<Real>|/type/Real> and multiply both boundaries
of the L<Range|/type/Range> object by that number.
say (1..2) * 2; # OUTPUT: «2..4␤»
=head2 sub infix:</>
multi sub infix:</>(Range:D \r, Real:D \v)
Takes an L<Real|/type/Real> and divide both boundaries
of the L<Range|/type/Range> object by that number.
say (2..4) / 2; # OUTPUT: «1..2␤»
=head2 sub infix:<cmp>
multi sub infix:<cmp>(Range:D \a, Range:D \b --> Order:D)
multi sub infix:<cmp>(Num(Real) \a, Range:D \b --> Order:D)
multi sub infix:<cmp>(Range:D \a, Num(Real) \b --> Order:D)
multi sub infix:<cmp>(Positional \a, Range:D \b --> Order:D)
multi sub infix:<cmp>(Range:D \a, Positional \b --> Order:D)
Compares two L<Range|/type/Range> objects. If you use a L<C<Real>|/type/Real>,
it will be compared to the L<Range|/type/Range> C<b..b>. If you use a
L<Positional>|/type/Positional>.
say (1..2) cmp (1..2) # OUTPUT: «Same␤»
say (1..2) cmp (1..3) # OUTPUT: «Less␤»
say (1..4) cmp (1..3) # OUTPUT: «More␤»
say (1..2) cmp 3 # OUTPUT: «Less␤»
say (1..2) cmp [1,2] # OUTPUT: «Same␤»
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit 0899a01

Please sign in to comment.