Operators

andthen & orelse

Full

Chain on definedness — continue if defined (andthen) or if undefined (orelse).

andthen and orelse sequence expressions by definedness, passing the left result along as the topic $_. andthen continues when the left is defined; orelse continues when it is undefined — the flow-control cousins of //.

andthen — continue if defined #

If the left side is defined, andthen evaluates the right with $_ set to it; otherwise it short-circuits to the undefined value.

say (5 andthen $_ * 2);
say (Nil andthen "unreached") // "skipped";
Output
10
skipped

5 is defined, so $_ * 2 runs (10); Nil is undefined, so the andthen short-circuits and // supplies skipped.

orelse — continue if undefined #

orelse is the mirror: it runs the right side only when the left is undefined.

say (Nil orelse "fallback");
say (5 orelse "unused");
Output
fallback
5

Notes #