📘 Prefix operator | in Perl 6

| flattens the compound objects into a list. For example, this operator should be used when you pass a list to a subroutine, which expects a list of scalars:

sub sum($a, $b) {
    $a + $b
} 

my @data = (10, 20);
say sum(|@data); # 30

Without the | operator, the compiler will report an error, because the subroutine expects two scalars and cannot accept an array as an argument:

Calling sum(Positional) will never work with declared signature ($a, $b)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s