In Junction§

See primary documentation in context for infix ~

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.

In Operators§

See primary documentation in context for prefix ~

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

String context operator.

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

In Operators§

See primary documentation in context for infix ~

multi sub infix:<~>(Any,   Any)
multi sub infix:<~>(Str:DStr:D)
multi sub infix:<~>(Buf:DBuf:D)
multi sub infix:<~>(Blob:D $aBlob:D $b)
multi sub infix:<~>(Junction:D \aJunction:D \b)

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␤» 
my $bob = Blob.new([1,2,3]);
my $bao = Blob.new([3,4,5]);
say $bao ~ $bob;     # OUTPUT: «Blob:0x<03 04 05 01 02 03>␤» 

The arity-1 version of this operator will be called when the hyper version of the operator is used on an array or list with a single element, or simply an element

say [~Blob.new([3,4,5]);     # OUTPUT: «Blob:0x<03 04 05>␤» 
say [~1|2;                   # OUTPUT: «any(1, 2)␤»