Skip to content

Commit 9f1f046

Browse files
committed
Adds push-exactly refs #1395
1 parent 46e94bc commit 9f1f046

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

doc/Type/IO/Path.pod6

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,8 @@ Delete all specified ordinary files, links, or symbolic links for which there
10101010
are privileges to do so. See L<rmdir> to delete directories.
10111011
10121012
The subroutine form returns the names of the files that were successfully
1013-
deleted. The method form returns C<True> on success, or
1014-
L<fails|/routine/fail> with L<X::IO::Unlink> if the operation could not be
1015-
completed.
1013+
deleted. The method form returns C<True> on success, or L<fails|/routine/fail>
1014+
with L<X::IO::Unlink> if the operation could not be completed.
10161015
10171016
=head2 method IO
10181017
@@ -1028,8 +1027,8 @@ Defined as:
10281027
10291028
method SPEC(IO::Path:D: --> IO::Spec)
10301029
1031-
Returns the L<IO::Spec|/type/IO::Spec> object that was (implicitly) specified at object
1032-
creation time.
1030+
Returns the L<IO::Spec|/type/IO::Spec> object that was (implicitly) specified at
1031+
object creation time.
10331032
10341033
my $io = IO::Path.new("/bin/bash");
10351034
say $io.SPEC; # OUTPUT: «(Unix)␤»
@@ -1074,12 +1073,12 @@ say "path/to/file".IO.changed.DateTime; # 2015-02-16T12:18:50Z
10741073
=head2 method mode
10751074
10761075
Return an L<IntStr> object representing the POSIX permissions of a file. The
1077-
Str part of the result is the octal representation of the file permission, like
1078-
the form accepted by the chmod(1) utility.
1076+
C<Str> part of the result is the octal representation of the file permission,
1077+
like the form accepted by the C<chmod(1)> utility.
10791078
10801079
=for code
1081-
say ~"path/to/file".IO.mode; # e.g. '0644'
1082-
say +"path/to/file".IO.mode; # e.g. 420, where sprintf('%04o', 420) eq '0644'
1080+
say ~"path/to/file".IO.mode; # e.g. '0644'
1081+
say +"path/to/file".IO.mode; # e.g. 420, where sprintf('%04o', 420) eq '0644'
10831082
10841083
The result of this can be used in the other methods that take a mode as an
10851084
argument.

doc/Type/Iterator.pod6

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ a simplistic subroutine re-implementation of the C<for> loop.
123123
124124
It would be more idiomatic to use C<while> or C<until>, and a sigilless variable.
125125
126-
=begin code :preamble<my $iterator = ().iterator; my &do = &say>
127-
until IterationEnd =:= (my \pulled = $iterator.pull-one) {
128-
do( pulled );
129-
}
130-
=end code
126+
=begin code :preamble<my $iterator = ().iterator; my &do = &say>
127+
until IterationEnd =:= (my \pulled = $iterator.pull-one) {
128+
do( pulled );
129+
}
130+
=end code
131131
132132
=head2 method push-exactly
133133
@@ -146,7 +146,41 @@ C<$count>.
146146
say (1 .. ∞).iterator.push-exactly(@array, 3); # OUTPUT: «3␤»
147147
say @array; # OUTPUT: «[1 2 3]␤»
148148
149-
The Iterator role implements this method in terms of C<pull-one>.
149+
The Iterator role implements this method in terms of C<pull-one>. In general,
150+
this is a method that is not intended to be called directly from the end user
151+
who, instead, should implement it in classes that mix the iterator role. For
152+
instance, this class implements that role:
153+
154+
=begin code
155+
class DNA does Iterable does Iterator {
156+
has $.chain;
157+
has Int $!index = 0;
158+
159+
method new ($chain where {
160+
$chain ~~ /^^ <[ACGT]>+ $$ / and
161+
$chain.chars %% 3 } ) {
162+
self.bless( :$chain );
163+
}
164+
165+
method push-exactly(Iterator:D: $target, int $count --> Mu) {
166+
return IterationEnd if $.chain.elems / 3 < $count;
167+
for ^($count) {
168+
$target.push: $.chain.comb.rotor(3)[ $_ ];
169+
}
170+
}
171+
172+
};
173+
174+
my $b := DNA.new("AAGCCT");
175+
for $b -> $a, $b, $c { say "Never mind" }; # Does not enter the loop
176+
my $þor := DNA.new("CAGCGGAAGCCT");
177+
for $þor -> $first, $second {
178+
say "Coupled codons: $first, $second";
179+
# OUTPUT: «Coupled codons: C A G, C G G␤Coupled codons: A A G, C C T␤»
180+
}
181+
=end code
182+
183+
This code, which groups DNA chains in triplets (usually called I<codons>) returns those codons when requested in a loop; if too many are requested, like in the first case C«for $b -> $a, $b, $c», it simply does not enter the loop since C<push-exactly> will return C<IterationEnd> since it is not able to serve the request for exactly 3 codons. In the second case, however, it requests exactly two codons in each iteration of the loop; C<push-exactly> is being called with the number of loop variables as the C<$count> variable.
150184
151185
=head2 method push-at-least
152186

0 commit comments

Comments
 (0)