Raku Programming/Junctions

Junctions
Junctions were originally implemented as part of a fancy Perl module to simplify some common operations. Let's say we have a complex condition where we need to test variable  against one of several discrete values:

This is a huge mess. What we want to do is basically create a list of values and ask "if  is one of these values". Junctions allow this behavior, but also do so much more. Here's the same statement written as a junction:

Types of Junctions
There are 4 basic types of junctions: any (logical OR of the components), all (logical AND of all components), one (logical XOR of all components), and none (logical NOR of the components).

List Operators
List operators construct a junction as a list:

Infix Operators
Another way to specify a junction is to use infix operators like we have already seen:

Notice that there isn't an infix operator to create  junctions.

Matching Junctions
Junctions, like any other data type in Raku, can be matched against using the smart match operator

Junctions
An  junction will only match if all the elements in it match the object. If any of the elements do not match, the entire match fails.

Junctions
A  junction will only match if exactly one of its elements match. Any more or any less, and the entire match fails.

Junctions
An  junction matches so long as at least one element matches. It could be one or any other number but zero. The only way for an  junction to fail is if none of the elements match.

Junctions
junctions only succeed in a match if none of the elements in the junction match. In this way, it's equivalent to the inverse of the  junction. If  succeeds,   fails. If  fails,   succeeds.