Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Hyper and race 🆕 / Exercises / A hyper map

Solution: A hyper map

Here is a possible solution to the task.

Code

say <apple banana pear cherry>.hyper.map(*.uc).grep(*.chars > 4).join(' ');

🦋 You can find the source code in the file hyper-map.raku.

Output

APPLE BANANA CHERRY

Comments

  1. .hyper runs the whole chain — the map that upper-cases and the grep that filters by length — across threads, in parallel.

  2. Because .hyper preserves order, the surviving words stay in their original sequence, so .join(' ') produces APPLE BANANA CHERRY. pear, with only four letters, is dropped.

Course navigation

A hyper map   |   A racing sum