Curso de Raku / Programación funcional, concurrente, reactiva y web / Programación funcional / Generadores / gather y take

Quiz — gather y take

¿Qué imprime el programa siguiente?

my @a = gather {
    for 1..5 {
        take $_ if $_ > 3;
    }
}

say @a;
0[1 2 3 4 5]
1[4 5]
0[1 2 3]
0[3 4 5]

El take solo se ejecuta cuando $_ > 3, así que a la lista únicamente se añaden 4 y 5. Todo lo demás se salta, dando [4 5].

gather y take   |   gather perezoso