Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cool.substr
  • Loading branch information
moritz committed Feb 23, 2015
1 parent b755f22 commit 1e44bb2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/Type/Cool.pod
Expand Up @@ -481,6 +481,30 @@ character removed.
say 'perl'.chop; # per
=head2 routine substr
method substr($from, $chars?)
sub substr(Str(Cool) $str, $from, $chars?)
Coerces the invocant (or in the sub form, the first argument) to
L<Str|/type/Str>, and returns the string starting from offset C<$from>. If
C<$chars> is supplied, at most C<$chars> characters are returned.
say 'zenith'.substr(2); # nith
say 'zenith'.substr(0, 3); # zen
# works on non-strings too:
say 20151224.substr(6); # 24
# sub form:
say substr "zenith", 0, 3; # zen
If the C<$from> parameter is a L<Callable|/type/Callable>, it is called with
the number of chars in the string as argument. This allows easy indexing
relative to the end:
say 20151224.substr(*-2); # 12
=head2 method IO
method IO() returns IO::Path:D
Expand All @@ -492,7 +516,7 @@ Coerces the invocant to L<IO::Path>.
=begin comment
TODO: sech, asech, cosech, acosech, cotanh, acotanh, cis, roots, log10,
unpolar, truncate, fmt, substr, substr-rw,
unpolar, truncate, fmt, substr-rw,
chomp, chrs, trans, index, rindex, ords,
split, match, comb, lines, words, subst, sprintf, printf, samecase,
EVAL
Expand Down

0 comments on commit 1e44bb2

Please sign in to comment.