Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / Live and on-demand supplies / Exercises / Two taps
Solution: Two taps
Here is a possible solution to the task.
Code
my $s = Supply.from-list(1, 2, 3);
my @doubled;
my @tripled;
$s.map(* * 2).tap(-> $v { @doubled.push($v) });
$s.map(* * 3).tap(-> $v { @tripled.push($v) });
say @doubled;
say @tripled;🦋 You can find the source code in the file two-taps.raku.
Output
[2 4 6]
[3 6 9]Comments
Supply.from-listis on-demand, so it replays its full sequence for each tap, independently.That lets the two taps run different pipelines over the same source: one doubles, one triples. Each sees all of
1, 2, 3, so the results are[2 4 6]and[3 6 9].
Course navigation
← Two taps | Tuning in late →