Skip to content

Commit

Permalink
Explicitly note coercion to string for .contains (#1413)
Browse files Browse the repository at this point in the history
* Explicitly note coercion to string for .contains

as per #992

* make link to traps more specific.

as per review

* Address comments

Address code review comments
   * remove some trailing whitespace 
   * add more examples
   * remove redundancy
  • Loading branch information
VynceMontgomery authored and zoffixznet committed Jul 21, 2017
1 parent 22792e1 commit cdae1ed
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions doc/Type/Cool.pod6
Expand Up @@ -1163,11 +1163,19 @@ L<Regex|/type/Regex> as a list of strings.
multi method contains(Cool:D: Str(Cool) $needle, Cool $start? --> Bool:D)
Returns C<True> if the invocant contains the C<$needle> at any position within
the string. If $start is provided skip as many characters.
Coerces the invocant and first argument to L<Str|/type/Str>, and searches for
C<$needle> in the string starting from C<$start>. Returns C<True> if C<$needle>
is found.
say "Hello, World".contains('Hello'); # OUTPUT: «True␤»
say "Hello, World".contains('hello'); # OUTPUT: «False␤»
say "Hello, World".contains(','); # OUTPUT: «True␤»
say "Hello, World".contains(',', 3); # OUTPUT: «True␤»
say "Hello, World".contains(',', 10); # OUTPUT: «False␤»
Note that because of how a L<List|/type/List> or L<Array|/type/Array> is
L<coerced|/type/List#method_Str> into a L<Str|/type/Str>, the results may
sometimes be surprising. See L<traps|/language/traps#Lists_become_strings,_so_beware_.contains>.
=head2 routine index
Expand Down

0 comments on commit cdae1ed

Please sign in to comment.