Documentation for routine ~
assembled from the following pages:
Language documentation: Operators §
From Operators
(Operators) prefix ~ §
multi sub prefix:<~>(Any --> Str)
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, Str)multi sub infix:<~>(Buf, Buf)multi sub infix:<~>(Blob , Blob )multi sub infix:<~>(Junction \a, Junction \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 = Blob.new([1,2,3]);my = Blob.new([3,4,5]);say ~ ; # 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)»
Class: Junction §
From Junction
(Junction) infix ~ §
Defined as:
multi sub infix:<~>(Str , Junction )multi sub infix:<~>(Junction , Str )multi sub infix:<~>(Junction \a, Junction \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 = 1|3|5;my = 2|4|6; my = ~ ;say ; # OUTPUT: «any(12, 14, 16, 32, 34, 36, 52, 54, 56)» say "Found 34!" if 34 == ; # OUTPUT: «Found 34!» my = "0" ~ ;say "Found 03" if "03" == ; # OUTPUT: «Found 03!» my = ~ "1";say "Found 11" if 11 == ; # 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.