Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Hyper and race 🆕 / Exercises / Hyper with a filter
Solution: Hyper with a filter
Here is a possible solution to the task.
Code
say (1..20).hyper.grep(* > 10).map(*²);🦋 You can find the source code in the file hyper-filter.raku.
Output
(121 144 169 196 225 256 289 324 361 400)Comments
*²is just Raku’s superscript spelling of* ** 2: the²is a postfix power operator, so*²is aWhateverCodethat squares its argument. Write* ** 2if you prefer..hyperparallelises the whole chain — thegrepthat keeps the numbers over10and themapthat squares them — while preserving order.Because the order is kept, the squares come back in the same sequence as their inputs (
11²,12², …,20²), giving(121 144 169 196 225 256 289 324 361 400).