Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Iterators / Exercises / Gather with a condition

Solution: Gather with a condition

Here is a possible solution to the task.

Code

my @vowels = gather {
    for 'education'.comb {
        take $_ if $_ ~~ / <[aeiou]> /;
    }
}

say @vowels;

🦋 You can find the source code in the file gather-vowels.raku.

Output

[e u a i o]

Comments

  1. .comb splits the word into single characters that the loop visits in order.

  2. take keeps a character only when it matches the vowel class, giving the vowels in the order they appear.

Course navigation

Gather with a condition   |   Lazy and infinite sequences