Skip to content
This repository
tree: 38b12096de
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 88 lines (53 sloc) 2.203 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
=begin pod

=TITLE class Range

    class Range is Iterable does Positional { ... }

Ranges serve two main purposes: to generate lists of consecutive
numbers or strings, and to act as a matcher to check if a number
or string is within a certain range.

Ranges are constructed using one of the four possible range operators,
which consist of two dots, and optionally a caret which indicates that
the endpoint marked with it is excluded from the range.

    1 .. 5
    1^.. 5 # start point excluded
    1 ..^5 # end point excluded
    1^..^5 # start and end point excluded

The caret is also a prefix operator for constructing numeric ranges
starting from zero:

    ^$x # same as 0 ..^ $x.Numeric

Iterating a range (or calling the C<list> method) uses the same semantics as
the C<++> prefix and postfix operators, ie it calls the C<succ> method on
the start point, and then generated elements).

Ranges always go from small to larger elements; if the start point is bigger
than the end point, the range is considered empty.

    for 1..5 { .say } # five iterations
    ('a' ^..^ 'f').list # 'b', 'c', 'd', 'e'
    5 ~~ ^5; # False
    (1.1..5).list; # (1.1, 2.1, 3.1, 4.1)

Use the C<...> sequence operator to produce lists of elements that
go from larger to smaller values, or to use offsets other than
increment-by-1.

=head1 Methods

=head2 min

    method min(Range:D:)

Returns the start point of the range.

=head2 excludes_min

    method excludes_min(Range:D:) returns Bool:D

Returns C<True> if the start point is excluded from the range, and C<False>
otherwise.

=head2 max

    method max(Range:D:)

Returns the end point of the range.

=head2 excludes_max

    method excludes_max(Range:D:) returns Bool:D

Returns C<True> if the end point is excluded from the range, and C<False>
otherwise.

=head2 bounds

    method bounds(Range:D:) returns Positional

Returns a list consisting of the start and end point.

=head2 list

    method list(Range:D:) returns List:D

Generates the list of elements that the range represents.

=head2 flat

    method flat(Range:D:) returns List:D

Generates the list of elements that the range represents.

=end pod
Something went wrong with that request. Please try again.