Today's revised revision of yesterday's new revisions
with amendments!

:-)


perl 6: method:
12/10/2019


perl 6: method:
12/10/2019


Also: "starts-with" and "ends-with"

A method is a routine that you feed: .foo

   $ p6 'say "abc".contains( "a" );'
   True

   $ p6 'say "abc".contains( "z" );'
   False

   $ p6 'my $x="\na\nb\nc\n"; for $x.lines -> $i {print "<$i>\n"};'
   <>
   <a>
   <b>
   <c>


Case insensitive contains:
    if "2018 Jul 7".fc.contains( "jul".fc ) {say "Yes";}
    Yes

    if "2018 xJul 7".fc.contains( "jul".fc ) {say "Yes";}
    Yes

    if "2018 xul 7".fc.contains( "jul".fc ) {say "Yes";}
    <nothing>

Warning: in the following, use "none" not "not" to negate if "coming soon"
             is found.  "not" will always return False.

my $x="strong>2018.2.0; Coming Soon</strong>"; say so $x.fc.contains("strong" & none "coming soon");
    False



multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos --> Bool)

"multi method"
    This means there are multiple ways to address this, as in

         multi method contains(Str:D: Cool:D $needle --> Bool)
         multi method contains(Str:D: Str:D $needle --> Bool)
multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos --> Bool)
         multi method contains(Str:D: Str:D $needle, Int:D $pos --> Bool)

"Str"
is the string data (Haystack) that will be operated on by the method (contains)

":D"
    means it wants actual data in the string and not a Nil.
    The jargon for this requirement is that is is constrained
    to an actual value

    If it wanted a Nil, it would say ":U" or constrained to
    a Nil

":"
    is the delimiter that tells you it is finished defining
    what is wants to be fed

"Cool:D $needle"
    means it wants a type Cool (string or number) for the
    substring ($needle) it is looking for in the Haystack (Str)

"Int(Cool:D)"
    Means it will change a type Cool into a type Int (integer)
    and the ":D" means it want some actual data and not a Nil.

"$pos"
    Is short of Position.  It is the starting index in the
    haystack (Str) to start looking for the substring
    (needle).  Index starts at zero by way of string
    convention in Perl 6

    $pos is an optional parameter.  Instead of $pos?
    for optional, they stated it with several "multi method"
    that do not include $pos.

"-->Bool"
    means it return True or False

Reply via email to