develooper Front page | perl.perl6.users | Postings from November 2021

junctions with given/when

Thread Next
From:
Joseph Brenner
Date:
November 2, 2021 16:45
Subject:
junctions with given/when
Message ID:
CAFfgvXVNnBjLqZjgHjWP0LOOpOeb5RSGfDkE_O6DNTgk3GJDrw@mail.gmail.com
A given/when construct using a junction isn't quite doing what I'd expect.

I'd thought that that would confirm that both elements were Int:

  say do given all(3,7) { when Int { "both are Int" }; default {"not
similar"} };
  ## not similar

But this does what I thought it would:

  say so do all(3,7) ~~ Int;
    # True

And the given seems to put the junction in $_ as expected:

  given all(3,7) { say $_; say $_.WHAT; }
    # all(3, 7)
    # (Junction)

And you can use that junction in a smartmatch explicitly

  given all(3,7) { say so $_ ~~ Numeric; }
    # True

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About