Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / react and whenever / Exercises / Collect with react
Solution: Collect with react
Here is a possible solution to the task.
Code
my @collected;
react {
whenever Supply.from-list('a', 'b', 'c') {
@collected.push($_.uc);
}
}
say @collected;🦋 You can find the source code in the file react-sum.raku.
Output
[A B C]Comments
The
wheneverbody runs once per value, upper-casing it and pushing it onto@collected.reactwaits for the single supply to finish, so by the timesayruns the array holds all three values in order:[A B C].