Skip to content

Commit 93aba54

Browse files
committed
update signatures of method contains and explain handling of Cool params
If $needle and/or $pos is of type Cool, this is no longer directly handled by a multi of Str.contains, but by a multi of Cool.contains. Hence, remove such signatures from here and instead add an explanation and a link to Cool.contains . Also, order the signatures in a way that's better to digest.
1 parent 921fd3c commit 93aba54

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

doc/Type/Str.rakudoc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ Examples:
4545

4646
=head2 method contains
4747

48-
multi method contains(Str:D: Cool:D $needle, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
49-
multi method contains(Str:D: Str:D $needle, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
50-
multi method contains(Str:D: Regex:D $needle --> Bool:D)
51-
multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
52-
multi method contains(Str:D: Str:D $needle, Int:D $pos, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
53-
multi method contains(Str:D: Regex:D $needle, Int:D $pos --> Bool:D)
54-
multi method contains(Str:D: Regex:D $needle, Cool:D $pos --> Bool:D)
48+
multi method contains(Str:D $:: Str:D $needle --> Bool)
49+
multi method contains(Str:D $:: Str:D $needle, Int:D $pos --> Bool)
50+
multi method contains(Str:D $:: Str:D $needle, :m(:$ignoremark)! --> Bool)
51+
multi method contains(Str:D $:: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark) --> Bool)
52+
multi method contains(Str:D $:: Str:D $needle, Int:D $pos, :m(:$ignoremark)! --> Bool)
53+
multi method contains(Str:D $:: Str:D $needle, Int:D $pos, :i(:$ignorecase)!, :m(:$ignoremark) --> Bool)
54+
multi method contains(Str:D $:: Regex:D $needle --> Bool)
55+
multi method contains(Str:D $:: Regex:D $needle, Int:D $pos --> Bool)
56+
5557

5658
Given a C<Str> invocant (known as the I<haystack>) and a first argument
5759
(known as the C<$needle>), it searches for the C<$needle> in the I<haystack>
@@ -71,6 +73,13 @@ invocant right from the start of the invocant string and returns C<True>.
7173
In the third case, the C<'Hello'> string is not found since we have
7274
started looking from the second position (index 1) in C<'Hello, World'>.
7375

76+
C<$needle> can also be of type C<Cool>, which will be coerced to C<Str>.
77+
Similarly, C<$pos> can be of type C<Cool>, which will be coerced to C<Int>.
78+
(Technically, these cases will take a detour over L<C<Cool.contains>|/type/Cool#method_contains>,
79+
which does the coercions and then calls C<Str.contains>.)
80+
81+
say "Hello, 12345".contains(5, "10.0"); # OUTPUT: «True␤»
82+
7483
Since Rakudo release 2020.02, the C<$needle> can also be
7584
a L<C<Regex>|/type/Regex> in which case the C<contains> method
7685
quickly returns whether the regex matches the string at least

0 commit comments

Comments
 (0)