September 2017
Beginner
402 pages
9h 52m
English
Objects of the Supply class have the grep and map methods, which can be used to filter the data of the stream similar to how the built-in functions with the same names do. Both grep and map methods create a new Supply object, to which you can connect a tap.
Consider the following example:
my $supply = Supply.interval(0.3);my $filtered = $supply.grep(* %% 2);$filtered.tap({ .say;});sleep 3;
We had a similar program in the On-demand supplies section earlier. This time, another supply, $filtered, is embedded in the data flow. It is created by the grep method called on the original $supply.
The filter itself is implemented by the WhateverCode block * %% 2. Only odd numbers pass from $supply to $filtered ...
Read now
Unlock full access