Skip to content

Commit

Permalink
Type::Str.lines: document new :$chomp parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
softmoth committed May 27, 2020
1 parent effde43 commit 73a6367
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions doc/Type/Str.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,12 @@ is returned by using features which explicitly set the top-level capture.
Defined as:
multi method lines(Str:D: $limit)
multi method lines(Str:D:)
multi method lines(Str:D: $limit, :$chomp = True)
multi method lines(Str:D:, :$chomp = True)
Returns a list of lines (without trailing newline characters), i.e. the
same as a call to C<$input.comb( / ^^ \N* /, $limit )> would.
Returns a list of lines. By default, it chomps line endings the same as a
call to C<$input.comb( / ^^ \N* /, $limit )> would. To keep line endings,
set the optional named parameter C<$chomp> to C<False>.
Examples:
Expand All @@ -626,6 +627,10 @@ Examples:
say "a\nb".lines.elems; # OUTPUT: «2␤»
say "a\n".lines.elems; # OUTPUT: «1␤»
# Keep line endings
say lines(:!chomp, "a\nb").raku; # OUTPUT: «("a\n", "b").Seq␤»
say "a\n".lines(:!chomp).elems; # OUTPUT: «1␤»
You can limit the
number of lines returned by setting the C<$limit> variable to a non-zero,
non-C<Infinity> value:
Expand Down

0 comments on commit 73a6367

Please sign in to comment.