On 2019-12-10 03:12, ToddAndMargo via perl6-users wrote:
Today's revised revision of yesterday's new revisions
with amendments!

:-)


At it again;

perl 6: method:
12/10/2019 #2


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


References:
    https://docs.raku.org/routine/contains
    https://docs.raku.org/routine/starts-with
    https://docs.raku.org/routine/ends-with
    https://docs.raku.org/routine/lines
    https://docs.raku.org/routine/fc
    https://docs.raku.org/routine/so
    https://docs.raku.org/syntax/Q


A method is a routine that you feed: Str.foo.

Think of "contains" as looking for a Needle in a Haystack.
You feed contains data and what you are lookig for.  In
return is tells you True or False

   say "abc".contains( "a" );
   True

   say "abc".contains( "z" );
   False

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


Case insensitive contains:
Note: "fc" converts you to lower case. It also converts weird charters to
          something on your keyboard

               say "XYßZ".fc;
               xyssz

    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>


Excluding something from the search:

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

say so Q[<strong>2018.2.0; Coming Soon</strong>].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

    Notes: $pos in NOT pointing at Bool
           --> means the return value
           it is not a pointer

Reply via email to