Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / Supplies / Tapping a supply

Quiz — Supplies

What does the following program print?

my $out = '';
Supply.from-list('a', 'b', 'c').tap(-> $v { $out ~= $v.uc });
say $out;
1ABC
0abc
0a b c
0C

The tap runs once for every value the supply emits. Each time, it upper-cases the value and appends it to $out, so a, b, c become A, B, C, joined into ABC. The block reacts to the whole stream, not just the last value — which is why the answer is not simply C.

Course navigation

Tapping a supply   |   Transforming a supply