Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / Supplies / Exercises / Count the emissions

Solution: Count the emissions

Here is a possible solution to the task.

Code

my $count = 0;
Supply.from-list(<a b c d e>).tap(-> $v { $count++ });
say $count;

🦋 You can find the source code in the file count-emissions.raku.

Output

5

Comments

  1. The tap runs once per emitted value, whatever the values are.

  2. Incrementing $count each time gives the total number of values, 5.

Course navigation

Count the emissions   |   Live and on-demand supplies