Skip to content

Commit aa3c53f

Browse files
committed
Add some badly needed Range documentation
1 parent de9e7f3 commit aa3c53f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

doc/Type/Range.pod

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Use the C<...> sequence operator to produce lists of elements that
4040
go from larger to smaller values, or to use offsets other than
4141
increment-by-1.
4242
43+
Use C<Inf> or C<*> (Whatever) to indicate an end point to be open-ended.
44+
45+
for 1..* { .say } # start from 1, continue until stopped
46+
for 1..Inf { .say } # the same
47+
4348
=head1 Methods
4449
4550
=head2 method min
@@ -74,6 +79,35 @@ otherwise.
7479
7580
Returns a list consisting of the start and end point.
7681
82+
=head2 method infinite
83+
84+
method infinite(Range:D:) returns Bool:D
85+
86+
Returns C<True> if either end point was declared with C<Inf> or C<*>.
87+
88+
=head2 method is-int
89+
90+
method is-int(Range:D:) returns Bool:D
91+
92+
Returns C<True> if both end points are C<Int> values.
93+
94+
=head2 method int-bounds
95+
96+
method bounds(Range:D:) returns Positional
97+
98+
If the C<Range> is an integer range (as indicated by L<is-int>, then this
99+
method returns a list with the first and last value it will iterate over
100+
(taking into account L<excludes-min> and L<excludes-max>). Returns a
101+
Failure If it is not an integer range.
102+
103+
=head2 method elems
104+
105+
method elems(Range:D:) returns Numeric:D
106+
107+
Returns the number of elements in the range, e.g. when being iterated over,
108+
or when used as a C<List>. Returns Inf if either end point was specified
109+
as C<Inf> or C<*>.
110+
77111
=head2 method list
78112
79113
method list(Range:D:) returns List:D
@@ -86,4 +120,20 @@ Generates the list of elements that the range represents.
86120
87121
Generates the list of elements that the range represents.
88122
123+
=head2 method pick
124+
125+
method pick(Range:D: ) returns Any:D
126+
method pick(Range:D: $number) returns Seq:D
127+
128+
Performs the same function as C<Range.list.pick>, but attempts to optimize
129+
by not actually generating the list if it is not necessary.
130+
131+
=head2 method roll
132+
133+
method roll(Range:D: ) returns Any:D
134+
method roll(Range:D: $number) returns Seq:D
135+
136+
Performs the same function as C<Range.list.roll>, but attempts to optimize
137+
by not actually generating the list if it is not necessary.
138+
89139
=end pod

0 commit comments

Comments
 (0)