Skip to content

Commit bcb5930

Browse files
committed
Document Cool.split
1 parent 8d1d524 commit bcb5930

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/Type/Cool.pod

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,35 @@ Unicode codepoint, and joining the characters.
542542
543543
This is the list-input version of L<chr>. The inverse operation is L<ords>.
544544
545+
=head2 routine split
546+
547+
multi method split( Str:D $delimiter, $limit = Inf, :$all)
548+
multi method split(Regex:D $delimiter, $limit = Inf, :$all)
549+
multi sub split( Str:D $delimiter, Str(Cool) $input, $limit = Inf, :$all)
550+
multi sub split(Regex:D $delimiter, Str(Cool) $input, $limit = Inf, :$all)
551+
552+
Coerces the invocant (or in the sub form, the second argument) to
553+
L<Str|/type/Str>, and splits it into pieces based on delimiters found in the
554+
string.
555+
556+
If C<$delimiter> is a string, it is searched for literally and not treated
557+
as a regex.
558+
559+
If the named parameter C<:all> is passed, the matches from C<$delimiter>
560+
are included in the result list.
561+
562+
Note that unlike in Perl 5, empty chunks are not removed from the result list.
563+
If you want that behavior, consider using L<comb> instead.
564+
565+
say split(';', "a;b;c").perl; # ("a", "b", "c").list
566+
say split(';', "a;b;c", :all).perl; # ("a", ";", "b", ";", "c").list
567+
say split(';', "a;b;c", 2).perl; # ("a", "b;c").list
568+
say split(';', "a;b;c", 2, :all).perl; #("a", ";", "b;c").list
569+
570+
say split(';', "a;b;c,d").perl; # ("a", "b", "c,d").list
571+
say split(/\;/, "a;b;c,d").perl; # ("a", "b", "c,d").list
572+
say split(/<[;,]>/, "a;b;c,d").perl; # ("a", "b", "c", "d").list
573+
545574
=head2 method words
546575
547576
method words(Int() $limit)
@@ -570,7 +599,7 @@ Coerces the invocant to L<IO::Path>.
570599
TODO: sech, asech, cosech, acosech, cotanh, acotanh, cis, roots, log10,
571600
unpolar, truncate, fmt, substr-rw,
572601
trans, index, rindex,
573-
split, match, comb, lines, subst, sprintf, printf, samecase,
602+
match, comb, lines, subst, sprintf, printf, samecase,
574603
EVAL
575604
576605
TODO: subroutine forms (where they exist)

0 commit comments

Comments
 (0)