Skip to content

Commit

Permalink
Document IO::CatHandle.handles
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Feb 25, 2018
1 parent 0e59d16 commit 55f79ab
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions doc/Type/IO/CatHandle.pod6
Expand Up @@ -246,6 +246,42 @@ my $cat = IO::CatHandle.new: $f1, $f2;
.say while $_ = $cat.getc; # OUTPUT: «I␤ ␤♥␤ ␤P␤e␤r␤l␤m␤e␤o␤w␤»
=end code
=head2 method handles
Defines as:
method handles(IO::CatHandle:D: --> Seq:D)
Returns a L<Seq> containing the currently-active handle, as well as all the
remaining source handles produced by calling L<next-handle>. If the invocant
has already been fully-consumed, returns an empty L<Seq>.
This method is especially handy when working with L<IO::ArgFiles>, where you
want to treat each filehandle separately:
# print at most the first 2 lines of each file in $*ARGFILES:
.say for flat $*ARGFILES.handles.map: *.lines: 2
It I<is> acceptable to call this method multiple times and C<.handles.head> is a
valid idiom for obtaining the currently-active handle. If, between
L<reification|/language/glossary#index-entry-Reify> of the elements of the
returned L<Seq> the handles get switched by some other means, the next
element produced by the L<Seq> would be the next handle of the invocant, not
the handle that would've been produced if no switching occured:
(my $file1 := 'file1'.IO).spurt: "1a\n1b\n1c";
(my $file2 := 'file2'.IO).spurt: "2a\n2b\n2c";
(my $file3 := 'file3'.IO).spurt: "3a\n3b\n3c";
my $cat := IO::CatHandle.new: $file1, $file2, $file3;
for $cat.handles {
say .lines: 2;
$cat.next-handle;
}
# OUTPUT: «(1a 1b)␤(3a 3b)␤»
Likewise, reifying the returned L<Seq> consumes the invocant's source handles
and once it is fully reified, the invocant becomes fully-consumed.
=head2 method IO
Defined as:
Expand Down

0 comments on commit 55f79ab

Please sign in to comment.