Skip to content

Commit 0899a01

Browse files
committed
document Range infixs #2739
1 parent af2115c commit 0899a01

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

doc/Type/Range.pod6

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ element can not be coerced into Numeric.
335335
method reverse(Range:D: --> Seq:D)
336336
337337
Returns a L<Seq|/type/Seq> where all elements that the C<Range> represents have
338-
been reversed. Note that reversing an infinite C<Range> won't produce any
338+
been reversed. Note that reversing an infinite C<> won't produce any
339339
meaningful results.
340340
341341
say (1^..5).reverse; # OUTPUT: «(5 4 3 2)␤»
@@ -379,6 +379,66 @@ C<self.elems>. Returns C<False> otherwise.
379379
say (6..10).EXISTS-POS(2); # OUTPUT: «True␤»
380380
say (6..10).EXISTS-POS(7); # OUTPUT: «False␤»
381381
382+
=head2 sub infix:<+>
383+
384+
multi sub infix:<+>(Range:D \r, Real:D \v)
385+
multi sub infix:<+>(Real:D \v, Range:D \r)
386+
387+
Takes an L<C<Real>|/type/Real> and adds that number to both
388+
boundaries of the L<Range|/type/Range> object. Be careful with
389+
the use of parenthesis.
390+
391+
say (1..2) + 2; # OUTPUT: «3..4␤»
392+
say 1..2 + 2; # OUTPUT: «1..4␤»
393+
394+
=head2 sub infix:<->
395+
396+
multi sub infix:<->(Range:D \r, Real:D \v)
397+
398+
Takes an L<C<Real>|/type/Real> and substract that number to both
399+
boundaries of the L<Range|/type/Range> object. Be careful with
400+
the use of parenthesis.
401+
402+
say (1..2) - 1; # OUTPUT: «0..1␤»
403+
say 1..2 - 1; # OUTPUT: «1..1␤»
404+
405+
=head2 sub infix:<*>
406+
407+
multi sub infix:<*>(Range:D \r, Real:D \v)
408+
multi sub infix:<*>(Real:D \v, Range:D \r)
409+
410+
Takes an L<C<Real>|/type/Real> and multiply both boundaries
411+
of the L<Range|/type/Range> object by that number.
412+
413+
say (1..2) * 2; # OUTPUT: «2..4␤»
414+
415+
=head2 sub infix:</>
416+
417+
multi sub infix:</>(Range:D \r, Real:D \v)
418+
419+
Takes an L<Real|/type/Real> and divide both boundaries
420+
of the L<Range|/type/Range> object by that number.
421+
422+
say (2..4) / 2; # OUTPUT: «1..2␤»
423+
424+
=head2 sub infix:<cmp>
425+
426+
multi sub infix:<cmp>(Range:D \a, Range:D \b --> Order:D)
427+
multi sub infix:<cmp>(Num(Real) \a, Range:D \b --> Order:D)
428+
multi sub infix:<cmp>(Range:D \a, Num(Real) \b --> Order:D)
429+
multi sub infix:<cmp>(Positional \a, Range:D \b --> Order:D)
430+
multi sub infix:<cmp>(Range:D \a, Positional \b --> Order:D)
431+
432+
Compares two L<Range|/type/Range> objects. If you use a L<C<Real>|/type/Real>,
433+
it will be compared to the L<Range|/type/Range> C<b..b>. If you use a
434+
L<Positional>|/type/Positional>.
435+
436+
say (1..2) cmp (1..2) # OUTPUT: «Same␤»
437+
say (1..2) cmp (1..3) # OUTPUT: «Less␤»
438+
say (1..4) cmp (1..3) # OUTPUT: «More␤»
439+
say (1..2) cmp 3 # OUTPUT: «Less␤»
440+
say (1..2) cmp [1,2] # OUTPUT: «Same␤»
441+
382442
=end pod
383443

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

0 commit comments

Comments
 (0)