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
.combsplits the word into single characters that the loop visits in order.takekeeps a character only when it matches the vowel class, giving the vowels in the order they appear.