Raku: a language that counts to infinity (Part 2)
In this part, let's look at infinite sequences from another angle: let's start collecting the values. First of all, Raku has a pair of built-in routines gather and take . They are useful when you need to collect data that's computed along the way. For example: my @data = gather { for ^50 { my $value = 100.rand.Int; take $value if 45 < $value < 55; } } say @data ; The program prints a few random…
Raku, a programming language, allows for the manipulation of infinite sequences through the use of built-in routines gather and take. These routines enable the collection of data computed along the way, even when dealing with infinite sequences. The language's approach to infinity makes the code clearer and more straightforward, as it focuses on applying actions to an infinite sequence and then taking only the necessary elements.
Examples provided include generating random numbers within a specific range, creating Pascal's triangle, and working with infinite sequences in various mathematical operations.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.