routine ~

Documentation for routine ~ assembled from the following types:

language documentation Operators

From Operators

(Operators) prefix ~

multi sub prefix:<~>(Any --> Str:D)

String context operator.

Coerces the argument to Str by calling the Str method on it.

language documentation Operators

From Operators

(Operators) infix ~

multi sub infix:<~>(Any,   Any)
multi sub infix:<~>(Str:DStr:D)
multi sub infix:<~>(Buf:DBuf:D)

This is the string concatenation operator, which coerces both arguments to Str and concatenates them. If both arguments are Buf, a combined buffer is returned.

say 'ab' ~ 'c';     # OUTPUT: «abc␤»

class Junction

From Junction

(Junction) infix ~

Defined as:

multi sub infix:<~>(Str:D $aJunction:D $b)
multi sub infix:<~>(Junction:D $aStr:D $b)
multi sub infix:<~>(Junction:D \aJunction:D \b)

The infix ~ concatenation can be used to merge junctions into a single one or merge Junctions with strings. The resulting junction will have all elements merged as if they were joined into a nested loop:

my $odd  = 1|3|5;
my $even = 2|4|6;
my $merged = $odd ~ $even;
say $merged#OUTPUT: «any(12, 14, 16, 32, 34, 36, 52, 54, 56)␤» 
say "Found 34!" if 34 == $merged#OUTPUT: «Found 34!␤» 
my $prefixed = "0" ~ $odd;
say "Found 03" if "03" == $prefixed#OUTPUT: «Found 03!␤» 
my $postfixed = $odd ~ "1";
say "Found 11" if 11 == $postfixed#OUTPUT: «Found 11!␤» 

On the other hand, the versions of ~ that use a string as one argument will just concatenate the string to every member of the Junction, creating another Junction with the same number of elements.