Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Junctions / Building junctions

Quiz — Junctions

What does the following program print?

say so 4 == all(2, 4, 6);
0True
1False
0all(2, 4, 6)
04

An all junction is true only when every value matches. The test 4 == all(2, 4, 6) asks whether 4 equals 2 and 4 and 6 — which it does not, so the result is False.

Curious what could make it True? The left side would have to equal each of 2, 4, and 6 at once. No single number can — but a junction on the left can: an any junction that includes all three of those values works, because then every one of the comparisons succeeds. The two sides need not be the same size — the left may carry extra values:

say so any(2, 4, 6, 8) == all(2, 4, 6); # True
say so any(2, 4)       == all(2, 4, 6); # False

The first is True because any(2, 4, 6, 8) still equals 2, 4, and 6 (the extra 8 is harmless). The second is False because the left side has no 6, so left == 6 fails.

Course navigation

Building junctions   |   Autothreading