Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Junctions / Exercises / Exactly one

Solution: Exactly one

Here is a possible solution to the task.

Code

say so one(1, 2, 3) == 2;

🦋 You can find the source code in the file any-match.raku.

Output

True

Comments

  1. A one junction is true only when exactly one value matches the comparison.

  2. Exactly one of 1, 2, 3 equals 2, so the result is True. If two of them matched (or none did), it would be False. The so collapses the junction to a plain Boolean.

Course navigation

Exactly one   |   All even