Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Coerce or transform with Types::Param

by tobyink (Canon)
on Mar 21, 2021 at 20:33 UTC ( #11130055=note: print w/replies, xml ) Need Help??


in reply to Re^2: Coerce or transform with Types::Param
in thread Coerce or transform with Types::Param

of is a shorthand for parameterizing a type. If you do something like this, it will fail:

if ( ArrayRef[Int]->check( \@numbers ) ) { ...; }

And you need to add some parentheses which look pretty ugly:

if ( ( ArrayRef[Int] )->check( \@numbers ) ) { ...; }

The of method look a little nicer:

if ( ArrayRef->of( Int )->check( \@numbers ) ) { ...; }

And where is a shorthand for creating a child type with an additional restriction.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130055]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-10-24 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?