Documentation for routine chomp

Documentation for routine chomp, assembled from the following types:

class Cool

From Cool

(Cool) routine chomp

Defined as:

sub chomp(Str(Cool))
method chomp()

Coerces the invocant (or in sub form, its argument) to Str, and returns it with the last character removed, if it is a logical newline.

say 'ab'.chomp.chars;                   # OUTPUT: «2␤» 
say "a\n".chomp.chars;                  # OUTPUT: «1␤» 

class Str

From Str

(Str) routine chomp

Defined as:

multi sub    chomp(Str:D  --> Str:D)
multi method chomp(Str:D: --> Str:D)

Returns the string with a logical newline (any codepoint that has the NEWLINE property) removed from the end.

Examples:

say chomp("abc\n");       # OUTPUT: «abc␤» 
say "def\r\n".chomp;      # OUTPUT: «def␤» NOTE: \r\n is a single grapheme! 
say "foo\r".chomp;        # OUTPUT: «foo␤»