Skip to content

Commit e15e61f

Browse files
committed
Cool.chomp, .ords, .chrs
1 parent 2370a3a commit e15e61f

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

lib/Type/Cool.pod

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ character removed.
481481
482482
say 'perl'.chop; # per
483483
484+
=head2 method chomp
485+
486+
method chomp()
487+
488+
Coerces the invocant to L<Str|/type/Str>, and returns it with the last
489+
character removed, if it is a logical newline.
490+
491+
say 'ab'.chomp.chars; # 2
492+
say "a\n".chomp.chars; # 1
493+
484494
=head2 routine substr
485495
486496
method substr($from, $chars?)
@@ -505,6 +515,33 @@ relative to the end:
505515
506516
say 20151224.substr(*-2); # 24
507517
518+
=head2 routine ords
519+
520+
method ords()
521+
sub ords(Str(Cool) $str)
522+
523+
Coerces the invocant (or in the sub form, the first argument) to
524+
L<Str|/type/Str>, and returns a list of Unicode codepoints for each character.
525+
526+
say "Perl 6".ords; # 80 101 114 108 32 54
527+
say ords 10; # 49 48
528+
529+
This is the list-returning version of L<ord>. The inverse operation in
530+
L<chrs>.
531+
532+
=head2 routine chrs
533+
534+
method chrs()
535+
sub chrs(*@codepoints) return Str:D
536+
537+
Coerces the invocant (or in the sub form, the argument list) to a list of
538+
integers, and returns the string created by interpreting each integer as a
539+
Unicode codepoint, and joining the characters.
540+
541+
say <80 101 114 108 32 54>.chrs; # Perl 6
542+
543+
This is the list-input version of L<chr>. The inverse operation is L<ords>.
544+
508545
=head2 method IO
509546
510547
method IO() returns IO::Path:D
@@ -517,7 +554,7 @@ Coerces the invocant to L<IO::Path>.
517554
518555
TODO: sech, asech, cosech, acosech, cotanh, acotanh, cis, roots, log10,
519556
unpolar, truncate, fmt, substr-rw,
520-
chomp, chrs, trans, index, rindex, ords,
557+
trans, index, rindex,
521558
split, match, comb, lines, words, subst, sprintf, printf, samecase,
522559
EVAL
523560

0 commit comments

Comments
 (0)